Advertisement
fauzanjeg

JKIT || Alter the WordPress search to return ONLY posts, no pages

Jul 17th, 2022
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. // Alter the WordPress search to return ONLY posts, no pages
  2. if ( ! is_admin() ) {
  3. function search_filter_pages( $query ) {
  4. if ( $query->is_search ) {
  5. $query->set( 'post_type', 'post' );
  6. }
  7. return $query;
  8. }
  9. add_filter( 'pre_get_posts', 'search_filter_pages' );
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement