- This topic has 9 replies, 4 voices, and was last updated 3 years ago by
Leo.
-
AuthorPosts
-
October 17, 2019 at 2:26 pm #1037569
yig
Hi there!
Is it possible to exclude a specific tag from wordpress search results? Also, how would it be possible to exclude specific pages from the results?
Is there a specific code for these so I can add to the functions.php file?
Thanks in advance!
October 17, 2019 at 3:24 pm #1037597Leo
StaffCustomer SupportHi there,
Just to make sure, are you referring to WordPress search widget or GP’s navigation search?
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 17, 2019 at 3:40 pm #1037615yig
Hi Leo,
Thanks for your response. I actually meant the GP navigation search (The one I enabled from the primary navigation menu)
I thought the one on the Off Canvas Panel was the same, but you made me realise I have it as a separate widget there. Maybe I’ll just remove that one π
October 17, 2019 at 7:56 pm #1037706Tom
Lead DeveloperLead DeveloperHi there,
This article might help: https://www.wpbeginner.com/plugins/how-to-exclude-specific-pages-authors-and-more-from-wordpress-search/
Specifically:
add_filter( 'pre_get_posts', function( $query ) { if ( $query->is_search && ! is_admin() ) $query->set( 'tag', '-19' ); } return $query; } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 17, 2019 at 11:59 pm #1037828yig
Thanks for your response Tom!
Actually I had tried that article before asking here but it gave me a functions.php error, so I thought maybe a different code is necessary for Generatepress. If that code works for you maybe it was about a plugin I use (Page Tags).
There are specific pages I wanted to exclude from the search.
As a workaround I created a new author, made it the author for these specific pages and excluded this author from the results (with the code from the same article). It worked well both for the widget and the nav search.
function wpb_search_filter( $query ) { if ( $query->is_search && !is_admin() ) $query->set( 'author','-24' ); return $query; } add_filter( 'pre_get_posts', 'wpb_search_filter' );
October 18, 2019 at 9:51 am #1038328Tom
Lead DeveloperLead DeveloperNice workaround! Very similar solution π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJanuary 14, 2020 at 4:06 am #1131536Nacho
Hello,
How would you exclude the GP search funcionanility from searching pages?
Thanks a lot.
January 14, 2020 at 9:38 am #1132054Leo
StaffCustomer SupportAny chance you can open a new topic for your question?
Thanks π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 15, 2020 at 3:08 am #1132664Nacho
Sure!
January 15, 2020 at 8:38 am #1133111Leo
StaffCustomer SupportThanks π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.