1

If I'm querying more than 1 post type, is it possible to ensure that I will always get at least 1 of each type?

$args = array(
    'post_type' => array( 'post', 'project' ),
    'posts_per_page' => 3,
    'ignore_sticky_posts' => true,
);

$recent_posts = new WP_Query( $args );

In this example, I'd like to ensure that I always have at least 1 post in the 3 posts that are returned.

I dislike how sticky posts behave as it ends up returning more than the 3 items requested and will impact other parts of my site.

  • 'ignore_sticky_posts' => false returns sticky posts, which according to your question you do not want? Right – Pieter Goosen May 19 '14 at 12:39
  • You need a UNION as per my answer to question marked as a duplicate. Getting a UNION to work with WP_Query is tricky, but possible. – s_ha_dum May 19 '14 at 12:41
  • @PieterGoosen correct. Copy/paste #fail from when I was testing out stick posts. – helgatheviking May 19 '14 at 12:49

Browse other questions tagged or ask your own question.