Advertisement
fauzanjeg

Add Custom Post Type in Search Page

Nov 29th, 2021
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.28 KB | None | 0 0
  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' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement