-
AuthorPosts
-
August 13, 2015 at 8:28 am #487008
Hi,
on https://kriesi.at/support/topic/portfolio-items-with-redirects-in-search-results/ you describe how to remove the portfolio post type from the search results.
May we also exclude a certain portfolio category (and its appropriate translated categories) from the search results?
Thanks, BerndAugust 13, 2015 at 12:47 pm #487149Hey profil77!
Please add following code to Functions.php file in Appearance > Editor
add_filter( 'pre_get_posts' , 'search_exc_cats' ); function search_exc_cats( $query ) { if( $query->is_admin ) return $query; if( $query->is_search ) { $query->set( 'category__not_in' , array( 30 ) ); } return $query; }
30 in array( 30 ) in the code is category ID. Replace it as needed
Cheers!
YigitAugust 17, 2015 at 9:50 am #488719Hi Yigit!
Sorry, the code does not yet exclude a certain portfolio category. But at the moment that’s no problem:
I need a few days to reorganize the portfolio items, then I will try again.
Please let the post open for a while.
Thanks, BerndAugust 17, 2015 at 9:36 pm #489147We looking forward to hearing from you :)
Regards,
JosueAugust 20, 2015 at 8:35 am #490581Hi Josue / Yigit!
The code does not yet exclude special portfolio categories.
Would you please have a look? You’ll find your code in Peter Dude’s Functions-Plugin.
Thanks, BerndAugust 20, 2015 at 9:06 am #490601Hi!
Please do try the following
// search filter function fb_search_filter($query) { if ( !$query->is_admin && $query->is_search) { $query->set('post_type', array('portfolio') ); // id of page or post } return $query; } add_filter( 'pre_get_posts', 'fb_search_filter' );
And do let us know if it worked out.
Regards,
BasilisAugust 20, 2015 at 9:40 am #490622Hi Basilis!
Thanks. Where exactly should I add the ids of the portfolio categories, that have to be excluded from the search?
Regards, BerndAugust 20, 2015 at 1:15 pm #490736Hey!
Basilis’ code should exclude portfolio post type from search results.
Cheers!
YigitAugust 20, 2015 at 7:33 pm #491033Hi!
Thanks, but sorry:
1) Basilis’ code doesn’t exclude the portfolio post type from search results.
2) Please have a look at post # 490581: we don’t want to exclude all portfolio posts,
but the posts of a special portfolio category.
Thanks, BerndAugust 20, 2015 at 10:21 pm #491102August 21, 2015 at 8:31 am #491199O.K. thanks, I’ll try it with a plugin.
Cheers, BerndAugust 21, 2015 at 9:48 am #491217You are welcome, glad to help :)
Regards,
JosueJanuary 11, 2019 at 7:21 pm #1052862Hello everyone!
I do not have many skills in English language, so I’m not sure if I understand if the codes above are correct for my case …
I would like to hide only the portfolio categories from the search results, or replace them with the pages where the article is shown … is it possible?
Thank you for your work!January 12, 2019 at 6:04 pm #1053163Hi Sachasilvestri,
Well, this code should work in the case where you want a portfolio category not to appear in search results.
Have you tried the code?
Best regards,
VictoriaJanuary 12, 2019 at 6:55 pm #1053197Hi Vittoria!
Thanks for your reply, just a clarification … for search results .. do you mean the search on google or the internal search of the site?
I need to hide the portfolio categories in the site’s internal search, that of the menu to be understood … ajax recearch … is this code right for my case?I put a demo link in private
Thanks for your help!
- This reply was modified 5 years, 11 months ago by Marco.
January 14, 2019 at 3:58 am #1053501Hi,
Have you tried using the suggested plugin above?
// https://wordpress.org/plugins/simply-exclude/
You can remove the code if you decided to use the plugin.
Best regards,
IsmaelJanuary 16, 2019 at 11:22 am #1054523Hi everybody ! Good day!
the Basilis code unfortunately did not work
The plug in indicated simply-exclude I saw that it has not been updated for 4 years. I’m really afraid of installing it.
I’d rather hide links to all portfolio categories with code if possible. It can be relative to the whole site, I do not want links that send to portfolio categories. The text may remain, but not the link.Thank you very much for your patience and professionalism
I await your response.January 21, 2019 at 5:40 am #1056419Hi,
Use this css code to remove the categories from the search results page.
.search-results span.blog-categories.minor-meta { display: none !important; }
Best regards,
IsmaelJanuary 21, 2019 at 6:08 am #1056425Fantastic ! it worked ! Thank you !!
January 21, 2019 at 7:28 am #1056461 -
AuthorPosts
- The topic ‘Remove portfolio category from search results?’ is closed to new replies.