WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On my main page, I want to show posts from 3 categories, and 1 custom post type.

Is there a way to get them together in one pre_get_posts function? Or do I need to query separately - once for the CPT and once for the posts from specific categories?

share|improve this question
up vote 1 down vote accepted

If you are after on post from category a, one from category b, another form category c and then finally a custom post type - each of these would have to be a separate query.

Think of these as 'secondary queries' - (the primary query being what lands you on the home page). So you'll want use seperate instances of WP_Query (see this related post).


$post_from_cat_a  = new WP_Query(array( 
    'category__name' => array('a'), 
    'posts_per_page'=> 1
if( $post_from_cat_a->have_posts() ){
    while( $post_from_cat_a->have_posts() ): $post_from_cat_a->the_post();
         //Display output here

$post_from_cat_b  = new WP_Query(array( 
    'category__name' => array('b'), 
    'posts_per_page'=> 1
if( $post_from_cat_b->have_posts() ){

etc. Don't forget to call wp_reset_postdata(); at the end.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.