• Skip to content
  • Skip to primary sidebar

Notes to Self

  • Aviation Weather from NOAA Plugin
    • KZZV
    • Bad Shortcode
    • Simple Metar
  • Chart Test
  • Keypress

Mark Chouinard / December 17, 2014

Add CPT to Search Query

add_action( 'pre_get_posts', 'pre_get_posts_example' );
function pre_get_posts_example( $query ) {
 
    if ( ! is_admin() && $query->is_main_query() ) {
     
        if ( $query->is_search ) {
            $query->set( 'post_type', array( 'post', 'movie' ) );
        }
 
    }
}

 

Filed Under: WordPress Tagged With: Actions

Previous Post: « Redirect to Post when search only returns 1
Next Post: Require Featured Image »

Primary Sidebar

Copyright © 2019 · Digital Pro on Genesis Framework · WordPress · Log in