Wordpress query category and tag

0

How do I search for posts by category and tag? I did it and it did not work:

query_posts(array( 
    'post_type' => 'noticias',
    'showposts' => 2,
    'category__and' => array(70),
    'tag__in'   => array(77),
) );
    
asked by anonymous 28.11.2017 / 23:59

1 answer

0

If I get it right, you want to get all the posts of the specific category of a Custom Post Type, right? category__and is used for standard wordpress post categories. In CPT for you to group post by categories you use taxonomy and to query use the parameter 'tax_query'.

Try this:

query_posts(array( 'post_type' => 'noticias',
   'posts_per_page' => 2,
   'tax_query' => array( array(
   'taxonomy' => 'ID_DA_TAXYNOMIA', 
   'field' => 'term_id', 
   'terms' => array( 70 ) ))));
    
05.12.2017 / 20:34