• Resolved teeboy4real

    (@teeboy4real)


    Hello,

    I recently searched for the keyword car in the search bar but the results returned were links to my pages, if there are no cars available it should show the message (There are no ads matching your search criteria.)

    This only occurs in the main page where I have the shortcode below
    [adverts_list search_bar=”enabled” columns=”3″ display=”grid” list_type=”all” posts_per_page=”30″]

    Kindly see image https://ibb.co/6Jz61MR

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter teeboy4real

    (@teeboy4real)

    Sorry this was my fault i had code in my functions.php causing this

    function SearchFilter($query) {
         if ($query->is_search) {
         $query->set('post_type', 'page');
         }
        return $query;
    }
    add_filter('pre_get_posts','SearchFilter');

    I fixed the issue using a better code below

    function exclude_all_pages_search($query) {
        if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
            $query->set('post_type', array( 'post', 'advert' ) );
        }
    }
    add_action('pre_get_posts','exclude_all_pages_search');
    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    ok thanks for the feedback, i am marking this thread as resolved then.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Wrong results for search query’ is closed to new replies.