WordPress.org

Ready to get started?Download WordPress

Forums

Need to Search Page Content (2 posts)

  1. devra
    Member
    Posted 1 year ago #

    I need to be able to search page content, and was trying to modify functions.php to allow me to search pages with search.php and searchform.php with this code I found in the forums:

    function SearchFilter($query) {
         if ($query->is_search) {
        // Insert the specific post type you want to search
         $query->set('post_type', array('post', 'page'));
       }
       return $query;
     }
    // This filter will jump into the loop and arrange our results before they're returned
     add_filter('pre_get_posts','SearchFilter');

    But this doesn't search my page content either. Can anyone tell me what I need to do so that WordPress will search page content?

    I tried the Search Everything plugin, which is supposed to give an option to allow the searching of page content, but the option for page content isn't there. I saw it on the install screen shot, so know it is supposed to exist.

    No reply on forum for Search Everything, nor from author.

    Can I make this work with functions.php? Is there a better way?
    Thanks.

  2. bcworkz
    Member
    Posted 1 year ago #

    The snippet you provided should return all posts and pages (instead of the usual posts only) that match the search terms in either title or content, using the default search box. I couldn't say why it's not working for you.

Topic Closed

This topic has been closed to new replies.

About this Topic