Ahmed Thahir
Ahmed Thahir

Reputation: 15

How to limit the search query and add filter in WordPress?

I am using a dynamix wordpress theme for new blog post website, when I try to filter posts, in the result page it is showing all the posts. I used many plugins as well to filter posts. such as search & filter and MDTF. still in the search result page it is showing all the available posts

Upvotes: 1

Views: 632

Answers (1)

Meet Makadia
Meet Makadia

Reputation: 336

Put below code in function.php file and your replace your posttype

function searchfilter($query) {

    if ($query->is_search) {
        $query->set('post_type', array( 'your-custom-post-type-name' ) );
    }

    return $query;
}
add_filter('pre_get_posts','searchfilter');

Upvotes: 2

Related Questions