WP_Query by a category id and a custom post_type

Question

I need to query all posts that belong to a given category (default, not custom) and a custom post type. As simple as that. The fact that it doesn’t work, to me, is ridiculous. Unless I’m missing something?

Here’s what I’ve tried:

$args=array(
    'posts_per_page' => 50, 
    //'taxonomy' => 'category',      
    'post_type' => 'my_custom_type'
    'category__in' => array($cat_id),
);
$wp_query = new WP_Query( $args );

then

$args=array(
    'posts_per_page' => 50,    
    'post_type' => 'my_custom_type'
    'tax_query' => array(
        array(
            'taxonomy' => 'category',
            'field'    => 'id',
            'terms'    => $cat_id,
        ),
    ),
 );
$wp_query = new WP_Query( $args );

and of course

$args=array(
    'posts_per_page' => 50, 
    'post_type' => 'my_custom_type'
    'category' => $cat_id,
);
$wp_query = new WP_Query( $args );

also, some combinations of adding/renaming/removing the $args keys.

Getting all posts by a post type and then looping through them and filtering by a category is not an effective option, I believe.

Please help.

0
, , aexl 7 years 2014-11-19T18:17:12-05:00 0 Answers 68 views 0

Leave an answer

Browse
Browse