foreach loop in wp_query witth multiple taxonomies (1 post)

  1. Bhuvnesh Gupta
    Posted 3 years ago #

    I need wp_query with multiple custom taxonomy.I wrote this following code but it is generating error

    Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')' in C:\xampp\htdocs\wpcompare\wp-content\plugins\custom-post-type-ui\replace_custom_tags_content.php on line 68

    This is my code`

    $args = array(
        'post_type' => 'product',
        'tax_query' => array(
            'relation' => 'AND',
    foreach($taxonomy_array as $taxonomy_array_value){
    $taxonomy_array_value_main = "'".$taxonomy_array_value."'";
    //echo $taxonomy_array_value_main;
    $term_value_array = array();
    foreach($term_array[$taxonomy_array_value] as $term_value){
        //echo $term_value;
    $term_name = "'" . implode("','", $term_value_array) . "'";
    //echo $term_name;
                'taxonomy' => $taxonomy_array_value_main,
                'field' => 'slug',
                'terms' => array( $term_name )
    $query = new WP_Query( $args );

    Can anyone tell me how to fix error OR if I am doing in a wrong way then tell me another solution for writing w-query for multiple custom taonomies

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by Bhuvnesh Gupta
  • This topic is not resolved
  • WordPress version: 3.5.1