-
AuthorPosts
-
December 4, 2017 at 9:26 pm #884791
Hi,
I am using the plug-in “Ultimate Category Excluder” to hide a specific category from the feed, page and archives.
Unfortunately the plug-in is not working for the search (although there is this option in the settings).How can I exclude this category from the search?
Furthermore there is a specific page I would like to exclude from the search as well, how can I do that?I already tried the following Functions.php code, which I found in this thread, but instead of excluding the categories with the id 5 an 9, it seems that it only includes these categories.
function avia_exc_post($query) { if ($query->is_search) { $query->set('cat','5,9'); } return $query; } add_filter('pre_get_posts','avia_exc_post');
I am looking forward for your input.
BR
FlorianDecember 6, 2017 at 10:43 am #885466Hey Florian,
Try like this
function avia_exc_post($query) { if ($query->is_search) { $query->set( 'category__not_in', array(5, 9) ); } return $query; } add_filter('pre_get_posts','avia_exc_post');
If you need further assistance please let us know.
Best regards,
VictoriaDecember 6, 2017 at 1:05 pm #885564Thanks a lot Victoria!!
That worked perfectly for the categories I want to exclude!And how can I exclude specific pages (with id) from the search?
BR
FlorianDecember 8, 2017 at 12:58 am #886313Hi,
Here is the first Google Result
http://www.wpbeginner.com/wp-tutorials/how-to-exclude-pages-from-wordpress-search-results/Best regards,
BasilisDecember 8, 2017 at 11:20 am #886422Hi Basil,
the code in your link is aiming to exclude all pages from WordPress search results, what I want to do is to exclude specific pages (by id).
And I already tried several things I found via google such as:
https://wp-dreams.com/forums/topic/exclude-specific-pages-in-search-results/
but non of them worked. Don’t know why, if you have an explanation I am happy to hear it.
The only thing I found which works is this plug-in , but I actually would prefer a php code, since I never know how plug-ins affect my page.
So if you have a solution I am happy to hear it.BR
December 8, 2017 at 12:14 pm #886447Hi catchbudapest,
Plugins are php code also and you can see the plugin code as well. While looking at it, you might find an idea or an answer.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.