Okay
  Public Ticket #469067
Limit what is searched for?
Closed

Comments

  • Richard started the conversation

    Hi there,

    Currently when I search for something on my site it brings up all pages, posts, products etc that contain those words.

    I'd like to exclude Pages if possible.

    How could I achieve this?

    Many thanks,


    R

  •  8,851
    Tahir replied

    Hey ,

    You can use this plugin: https://wordpress.org/plugins/search-everything/ .

    Thanks


    ThemeNectar Support Team 

  • Richard replied

    Couldn\'t get that plugin to work, but I did fix it by putting this code into my functions.php file...

    // Set search results to display only \'product\' post type results
    if ( !is_admin() ) {
    function searchfilter($query) {
        if ($query->is_search && !is_admin() ) {
            $query->set(\'post_type\',array(\'product\'));
        }
    return $query;
    }
    add_filter(\'pre_get_posts\',\'searchfilter\');
    }
  •  8,851
    Tahir replied

    Cheers.


    ThemeNectar Support Team