marko krstić

Collections

Archives

Limit search to post type

If you need to display only certain post type ( page, post, custom post) you need to add this to function.php

function searchfilter($query) {
 
    if ($query->is_search && !is_admin() ) {
        $query->set('post_type',array('post','page'));
    }
 
return $query;
}
 
add_filter('pre_get_posts','searchfilter')

On line 4 change what post type you need.

Source: https://www.wpbeginner.com/wp-tutorials/how-to-limit-search-results-for-specific-post-types-in-wordpress/

Let's Connect

Feel free to reach out for collaborations or just a friendly hello ?
[email protected]
linkedininstagramdribbblefacebook-official