• Skip to primary navigation
  • Skip to main content

Genesis Community

Resources for Genesis WordPress Theme Users

  • Facebook
  • Twitter
  • Slack
  • Wiki
  • Login
You are here: Home / Wikis / WordPress / Restrict searches to posts only

Restrict searches to posts only

//* Restrict searches to posts only
add_filter( 'pre_get_posts', 'bourncreative_search_filter' );
function bourncreative_search_filter( $query ) {

    if ( $query->is_search && ! is_admin() && $query->is_main_query() ) {
          $query->set( 'post_type', 'post' );
    }

    return $query;

}
Source: https://genesiswp.slack.com/archives/C02N454K9/p1509461784000506
Notes:

will accept an array of post types as well. $query->set( 'post_type', array( 'post', 'cpt_1', 'cpt_2' ) );

Posted by: Sridhar Katakam Category: WordPress Tags: brian bourn, pre_get_posts

« Page title for category archive
Remove landing pages from the search results »

Copyright © 2026 · Genesis Sample on Genesis Framework · WordPress · Log in