• Henry

    (@voodoohoodoo)


    Hi folks,
    just wondering how I can modify the search results to give me only Pages, not posts. Is this something in Seach.php? or Functions.php?
    Have googled the issue but it seems there are too many different ways to do this which has left me more confused!
    Any help would be spiffing! Ta!

    H

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this in your theme’s functions.php:

    function mySearchFilter($query) {
      $post_type = 'page';
      if($query->is_main_query()){
        if ($query->is_search) {
          $query->set('post_type', $post_type);
        }
      }
    };
    add_action('pre_get_posts','mySearchFilter');

    Thread Starter Henry

    (@voodoohoodoo)

    Ok! I think that has done it. Many thanks for such a fast response.
    cheers
    Henry

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Edit search to bring results of pages only, NOT posts’ is closed to new replies.