Monday, August 1, 2022
HomeWordPress Developmentphp - WordPress Conditional / A number of Taxonomy Question

php – WordPress Conditional / A number of Taxonomy Question


I’m attempting to create a customized WordPress taxonomy question with a number of however conditional statements. Nonetheless I’m having points when multiple taxonomy question is added to the assertion.

$tax_query = array('relation' => 'AND');

if (isset($_POST['category_id'])) {
  $tax_query[] =  array(
    'taxonomy' => 'class',
    'subject'    => 'term_id',
    'phrases'    => $_POST['category_id'],
  );
}

if (isset($_POST['insight_id'])) {
  $tax_query[] =  array(
    'taxonomy' => 'perception',
    'subject' => 'term_id',
    'phrases' => $_POST['insight_id'],
  );
}

if (isset($_POST['industry_id'])) {
  $tax_query[] =  array(
    'taxonomy' => 'business',
    'subject' => 'term_id',
    'phrases' => $_POST['industry_id'],
  );
}

$question = new WP_Query(
  array(
    'posts_per_page' => -1,
    'tax_query' => $tax_query,
  )
);

My code is above.

If solely Class ID exists, then the question ought to run as regular but when for instance Class and an Perception ID exists, then it ought to discover all posts with the taxonomy in Class and Perception. The identical for Business ID… I can not determine the place I’ve gone fallacious or why this does not work?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments