Wp query adding 0=1 in the query and results disappear, I am trying to adding multiple taxonomies in the query but it is producing 0=1. I am trying to fetch results from multiple taxonomies and in case of all I am passing a blank array to get all results
$category = array('');
$post_regions = array('');
$post_tag = array('');
$post_categories = array('');
if($_POST['pageType'] !== "all"){
$category = array (
'taxonomy' => 'category',
'field' => 'slug',
'operator' => 'IN',
'terms' => explode(',', $_POST['pageType'])
);
}
if($_POST['regions'] !== "default"){
$post_regions = array(
'taxonomy' => 'post_regions',
'field' => 'slug',
'operator' => 'IN',
'terms' => explode(',', $_POST['regions'])
);
}
if($_POST['topics'] !== "All"){
$post_tag = array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => explode(',', $_POST['topics']),
'operator' =>'IN'
);
}
$args = array(
'post_type' => 'post',
'orderby' => 'publish_date',
'posts_per_page' => -1,
'order' => 'DESC',
'post_status' => 'publish',
'date_query' => array(
'relation' => 'OR',
$dates
),
'tax_query' => array(
'relation' => 'AND',
$category,
$post_regions,
$post_tag,
$post_categories,
),
);
$query = new WP_Query( $args );
Define the empty array like this:
array();
If you define a array the way you do:
array('');
then array[0] is set.
Regards Tom
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With