Taxonomy Query (tax_query) using WP_Query example Print

  • 4

Taxonomy Query (tax_query) using WP_Query

Example:

                $args=array(
                    'post_type' => 'your_post_type',
                    'post_status' => 'publish',
                    'orderby' => 'title',
                    'order' => 'DESC',
                    'posts_per_page' => -1,
                    'tax_query' => array(
                    array(
                        'taxonomy' => 'your_taxonomy_slug',
                        'field' => 'slug',
                        'terms' => array( 'taxonomy_term1','taxonomy_term2' )
                    )
                    )
                );
 
                $result = new WP_Query( $args );
 
                 // The Loop
                if ( $result->have_posts() )  {
                    while ( $result->have_posts() ) {
                        $result->the_post();

                        // this is your loop

                    }

                } else {
                     // nothing
                }

Was this answer helpful?

« Back