From cb930a79d19aa887cabebc3308685662dae31a5d Mon Sep 17 00:00:00 2001 From: ashrafuddin1496 Date: Wed, 11 Aug 2021 20:09:40 +0600 Subject: [PATCH] extended tax query realtionship and nesting --- taxquery.php | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/taxquery.php b/taxquery.php index f87fe75..0405d0a 100644 --- a/taxquery.php +++ b/taxquery.php @@ -2,30 +2,41 @@ /** * Template Name: Tax Query Example */ - $philosophy_query_args = array( - 'post_type'=>'book', - 'post_per_page'=>-1, - 'tax_query'=>array( - 'relation'=>'AND', + 'post_type' => 'book', + 'posts_per_page' => - 1, + 'tax_query' => array( + 'relation' => 'AND', array( - 'taxonomy'=>'language', - 'field'=>'slug', - 'terms'=>['english'], + 'relation' => 'AND', + array( + 'taxonomy' => 'language', + 'field' => 'slug', + 'terms' => array( 'english' ) + ), + array( + 'taxonomy' => 'language', + 'field' => 'slug', + 'terms' => array( 'arabic' ), + 'operator' => "NOT IN" + ) ), array( - 'taxonomy'=>'language', - 'field'=>'slug', - 'terms'=>['bangla'], - 'operator'=>'NOT IN' - ) - ), + 'taxonomy' => 'genre', + 'field' => 'slug', + 'terms' => array( 'history' ) + ), + + + ) ); -$philosophy_query_posts = New WP_Query($philosophy_query_args); -while ($philosophy_query_posts->have_posts()){ - $philosophy_query_posts->the_post(); +$philosophy_posts = new WP_Query( $philosophy_query_args ); +//echo $philosophy_posts->found_posts; + +while ( $philosophy_posts->have_posts() ) { + $philosophy_posts->the_post(); the_title(); - echo '
'; + echo "
"; } wp_reset_query(); \ No newline at end of file