Latest Tech and Tips

How To Limit Search Results For Specific Post Types in WordPress

0

Have you ever before questioned how you can limit your search engine result to specific post types? Its not really difficult. We’ve currently revealed you how to disable the search function in WordPress by changing the functions.php documents. Now we’re mosting likely to do the very same point other than to filter our search engine result.

Open your functions.php documents and also include the adhering to codes:

feature searchfilter($ query) {

if ($ query->> is_search && & &! is_admin()) {
$ query->> collection(' post_type', range(' post',' web page'));.
}

return $query;.
}

add_filter(' pre_get_posts',' searchfilter');.

Notice the line that states

$ query->> collection(' post_type', range(' post',' web page'));.

You can filter the search engine result by altering the worths in the range variable. Right currently it is readied to show blog posts and also web pages however you can customize it to show anything you desire.