Exclude custom taxonomy from search results and archive pages

Copy the following snippet and paste it into the code of your theme, preferably in the functions.php file: /* Exclude a Category from Search Results */ 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 ) ); // Cat ID … Read more

Complex Search functionality. Advice needed

There’s a few ways you could do this. I once wrote some extended code to integrate Apache Solr with WordPress search and BuddyPress and that added a lot of power. With something like Apache Solr you can customize weight and do some interesting things. Solr is a full fledged search engine and you will need … Read more

How do i change the search permanent links

This snippet should solve your problem. Just put it into your functions.php file. function my_insert_rewrite_rules( $rules ) { $newrules = array(); $newrules[‘search/([^/]+)/post_type/([^/]+)/?$’] = ‘index.php?s=$matches[1]&post_type=$matches[2]’; return $newrules + $rules; } add_filter( ‘rewrite_rules_array’,’my_insert_rewrite_rules’ ); function my_flush_rewrite_rules() { flush_rewrite_rules(); } add_action( ‘after_switch_theme’, ‘my_flush_rewrite_rules’ ); You will have to flush rewrite rules after adding this code, before it will … Read more

WordPress 3.6, searchform.php problems

The answer is taken from WordPress.org Support Forum thread: » 3.6 upgrade – searchform.php not working As salcode said: Adding this code to your functions.php should do the trick: function search_form_no_filters() { // look for local searchform template $search_form_template = locate_template( ‘searchform.php’ ); if ( ” !== $search_form_template ) { // searchform.php exists, remove all … Read more

Manual excerpts for pages not working on Search

You’re confusing “post type support” – which means enabling “feature” (and therefore MetaBoxes) for a post – with templating. Go into your theme, search for the search.php template in the folder. Add a Child Theme Add a file named search.php to your Child theme and copy/paste the content of your parent themes template file in … Read more

Exclude top-level pages from search results

I wonder if this will work for you: function search_filter( $query ) { if( $query->is_search AND $query->is_main_query() ) { // $query->set( ‘post_parent__not_in’, array( 0 ) ); // We comment this out here $query->set( ‘post_type’, array( ‘post’, ‘page’ ) ); } return $query; } add_action( ‘pre_get_posts’, ‘search_filter’ ); and function wpse_120638( $where, $query ) { global … Read more