MD. Atiqur Rahman
MD. Atiqur Rahman

Reputation: 2173

Wordpress query_posts for Multiple variable not working

I was trying to get results of the posts which has category and my custom taxonomy Type . I am trying this

$args = 'category=' . $cat . '&Type='.$type.'&order=ASC';
  query_posts($args);

I am receiving $cat and $type from a GET request. The problem is it is pulling up all the posts that belong to the Type taxonomy ireespective to category

Your help is appreciated.

Thanks !

Upvotes: 0

Views: 137

Answers (2)

MD. Atiqur Rahman
MD. Atiqur Rahman

Reputation: 2173

I had to do this :

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'category',
            'field'    => 'slug',
            'terms'    => array($cat),
        ),
        array(
            'taxonomy' => 'Type',
            'field'    => 'slug',
            'terms'    => array( $type ),
        ),
    ),
);
$query = new WP_Query( $args );

instead using query_posts()

Thank you!

Upvotes: 1

Naisa purushotham
Naisa purushotham

Reputation: 913

can you try this

  $args = 'cat=' . $cat . '&post_type='.$type.'&order=ASC';
  query_posts($args);

for more reference: https://codex.wordpress.org/Function_Reference/query_posts

Upvotes: 0

Related Questions