Search code examples
phpwordpresscategoriescustom-post-type

Wordpress get custom post type posts by category


Hi I have some problem with custom post type categories, I try to get all post that have some category but it output all post. Can you help me please. Thank you.

my code

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'post_type' => "collection-posts",
    'category'=> 1,
    'posts_per_page' => 12,
    'paged' => $paged
);
query_posts($args);

but it give all posts. I don't understand why


Solution

  • The arguments key should be cat, not category:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
        'post_type' => "collection-posts",
        'cat' => 1,
        'posts_per_page' => 12,
        'paged' => $paged
    );
    query_posts($args);