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 added a new custom post type to my Wordpress theme but it refuses to show on the homepage. I tried setting

<?php query_posts( array( 'post_type' => array('post', 'reviews') ) );?>

but it doesn't seem to work, it just loops my normal posts. Any suggestions would be greatly helpful.

Here's a pastie of my index if anyone wants to see it:


share|improve this question
Please add debug information to your question to make answers possible. – toscho Oct 26 '12 at 21:34
up vote 3 down vote accepted

I would avoid the use of query_posts -- it forces another database hit. There are plenty of other ways to hook in and change the query before posts are fetches. pre_get_posts is one of them.

To display multiple post types on the home page (pages and posts in this example):

add_action('pre_get_posts', 'wpse70606_pre_posts');
 * Change that query! No need to return anything $q is an object passed by 
 * reference {@link http://php.net/manual/en/language.oop5.references.php}.
 * @param   WP_Query $q The query object.
 * @return  void
function wpse70606_pre_posts($q)
    // bail if it's the admin, not the main query or isn't the (posts) page.
    if(is_admin() || !$q->is_main_query() || !is_home())

    // whatever type(s) you want.
    $q->set('post_type', array('post', 'page'));

This would go in your themes's functions.php file or in a plugin.

share|improve this answer
Can you better explain where I would put this? In the index, loop, or functions? – hiiambo Oct 26 '12 at 21:48
see my edit: in functions (probably sans the open <?php or in a plugin. – chrisguitarguy Oct 26 '12 at 21:51
Worked great! Thank you! – hiiambo Oct 26 '12 at 22:00

I would try this first:

global $wp_query;
$args = array_merge( $wp_query->query, array( 
  'posts_per_page' => -1,
  'post_type' => 'any',
) );

query_posts( $args );

This will keep the original query, and display every single post (-1 means "all posts"), of every post type. That should help you troubleshooting the issue.

share|improve this answer
Where would this go? Into the loop or into index? – hiiambo Oct 26 '12 at 21:40
get_posts() would be better, because query_posts() will overwrite the main query object. – toscho Oct 26 '12 at 22:02

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.