fauzanjeg

Add Custom Post Type in Search Page

Nov 29th, 2021
622
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Add Custom Post Type in Search Page */
  2. function include_cpt_search( $query ) {
  3.     if ( $query->is_search ) {
  4.         $query->set( 'post_type', array( 'post', 'page', 'custom_post_type', 'test-custom-post-typ' ) );
  5.     }
  6.     return $query;
  7. }
  8. add_filter( 'pre_get_posts', 'include_cpt_search' );
RAW Paste Data