I'm trying to load only two types of posts ( 'news' and 'reviews' ) in home page using pre_get_posts:

// Load Home Page Posts( reviews and news )
function search_home_posts( $query ) {
    if( $query->is_home() && $query->is_main_query() && !is_admin() ) {
        $query->set( 'post_type', array( 'reviews', 'news' ) );
add_action( 'pre_get_posts', 'search_home_posts' );

But it doesn't seem to do nothing, since all post types and pages are shown in the home page. Any idea of what is happening?

1 Answer 1


There is nothing wrong with that code. It's correct and working fine for me on a default installation.

Change to using the default theme. Does it work now? If so, then there's something wrong with your theme.

Disable other irrelevant plugins. Does it work now? If so, then one of those plugins was interfering.

Eliminate the possible conflicts until the code works the way you expect it to work.

  • My mad, I was creating an other query object in the home template. You are right. It works perfect.
    – Manolo
    Dec 23, 2013 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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