WordPress.org

Ready to get started?Download WordPress

Forums

Get all custom_post_type posts + blog posts from one category in a single query (5 posts)

  1. ragulka
    Member
    Posted 2 years ago #

    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.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  3. ragulka
    Member
    Posted 2 years ago #

    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?

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  5. ragulka
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic