WordPress.org

Ready to get started?Download WordPress

Forums

foreach loop in wp_query witth multiple taxonomies (1 post)

  1. Bhuvnesh Gupta
    Member
    Posted 10 months 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',
    //print_r($taxonomy_array);
    
    foreach($taxonomy_array as $taxonomy_array_value){
    $taxonomy_array_value_main = "'".$taxonomy_array_value."'";
    //echo $taxonomy_array_value_main;
    $term_value_array = array();
    //print_r($term_array[$taxonomy_array_value]);
    foreach($term_array[$taxonomy_array_value] as $term_value){
        //echo $term_value;
    
            array_push($term_value_array,$term_value);
        }
    
    $term_name = "'" . implode("','", $term_value_array) . "'";
    //echo $term_name;
            array(
                '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

Reply

You must log in to post.

About this Topic

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