I am trying to create a filter using WP_Query() in which I am sending term id by POST method via AJAX,
These term ids are from multiple taxonomies:
- Collateral_services
- Collateral_Technology
- Collateral_Industry
I've created a WP_Query which works fine if $ser , $tech , $ind are not blank.
$cat_ids = $_POST['category'];
$ser = $_POST['services'];
$tech = $_POST['technology'];
$ind = $_POST['industry'];
$paged = $_POST['page']+1;
$args = array(
'post_type' => 'page',
'category__in' => $cat_ids,
'post_status' => 'publish',
'orderby' => 'DESC',
'paged' => $paged,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'Collateral_services',
'field' => 'id',
'terms' => $ser,
),
array(
'taxonomy' => 'Collateral_Technology',
'field' => 'id',
'terms' => $tech,
),
array(
'taxonomy' => 'Collateral_Industry',
'field' => 'id',
'terms' => $ind,
),
),
);
$new = new WP_Query($args);
But what I want is to create dynamic kind of query, query should work if user is choosing only Collateral_services or Collateral_Technology or Collateral_Industry, or by combination or any two or all together,
Can someone help to make it Dynamic?
Any Help Appreciated.