0

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 !

1
  • Please don't use query_posts() for fetching posts. For general post queries, use WP_Query() or get_posts(). Commented May 23, 2016 at 10:57

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Just For information... Don't use query_posts, why? click here
Thank you So much for sharing!
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.