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

I'm looking for a way to balance the content at the homepage of my blog:

the blog has a few post types like Poscasts, Videos and Blog and I'd like to have let's say 10 Posts on the homepage, but I'd like to make 5 of them always the lastest Blog.

Making 3 separated boxes don't solve my problem because the posts are mixed togheter and there won't always be as many posts of the other types.

I could think of the solution for it on pure PHP , but I'd like to get a idea on how to do this using the wordpress API, any help , reference will be welcome!

share|improve this question
Yea, it's far from being effective or "the right way" of doing this, but anyway +1. Appreciate the effort you've taken to show what you want to achieve. :) – kaiser Mar 22 '12 at 23:06
I'd suggest you use the standard way of doing things - secondary loops; just issue 3 get_posts-type queries; these will come with the added benefit of caching (whichever backend is available) and security among others. codex.wordpress.org/The_Loop#Multiple_Loops which I'm sure you seen. – soulseekah Mar 23 '12 at 2:21
+ 1 for your effort! – Rutwick Gangurde Mar 23 '12 at 3:58
up vote 1 down vote accepted

If you are still looking for an alternative that may be faster this may help you:

function customBlogFeed() {

// The Query 
$the_query = new WP_Query( array ( 'post_type' => array( 'post', 'page', 'movie', 'book'), 'posts_per_page' => '6' ) );
//Your post_type array is a list of random post_types. You can add whatever you'd like to match your system.

// The Loop 
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

  <?php the_title(); ?>
      <?php the_content(); ?>

<?php endwhile;

// Reset Post Data

Then to get it's output put <?php customBlogFeed(); ?> wherever you'd like this to output.

If you really want to get fancy you can hook into the post_limits Filter and limit how many posts per post type are displayed. I hope this helps you on your quest.

PS - Look into WP_Query, it will really help you out.

After some research you might actually want to look into post_clauses to get those SQL characterizations done with WP3.1+ Syntax

share|improve this answer

So, after a few months. I found the answer to your exact question:

add_action('pre_get_posts', 'custom_main_query', 1);
function custom_main_query( $query ) {
  if ( $query->is_main_query() && is_home() ) { 
  //be super careful with this and to be safe, keep the is_home() 
  //bit there, I've had some funny results without it.

    $query->query_vars['posts_per_page'] = 3; //displays 3 posts ;)
    $query->query_vars['post_type'] = array('post'); //and if you wanted multiple cpts <3

    return $query;



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.