• ragulka

    (@ragulka)


    I am trying to display the 10 latest custom_post_type posts and blog posts on my homepage in a single query – so that I have 10 posts in total, sorted by post_date in DESC order, containing all posts from my custom_post_type and blog posts from a certain category.

    This query doesn’t seem to work:

    $args = array (
        'cat' => 3,
        'post_type' => array ( 'custom_post_type', 'post' )
    );

    It fetches only the blog posts from the category 3, but no custom_post_type posts.

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    (@esmi)

    You only asked for posts from category 3 in your query ('cat' => 3,).

    Thread Starter ragulka

    (@ragulka)

    Yes, but I assumed that cat => 3 applies to posts only, not custom_post_type…
    I guess it doesn’t work that way – but how can I get the same result?

    esmi

    (@esmi)

    I think you’d need to use 2 queries for that.

    Thread Starter ragulka

    (@ragulka)

    That won’t work either, because I need a total of 10 latest items, regardless if they’re blog posts or custom_posts…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get all custom_post_type posts blog posts from one category in a single query’ is closed to new replies.