I came across a recent bug today on a client site where the excellent ‘Search Everything’ plugin was updated to the latest version (currently 8.1.3) and the search suddenly returned no results on the website.
I narrowed it down to the ‘category exclude’ option as unchecking this box in the admin area made the plugin work as it should again. As you can see below, I had just one category in there for exclusion:
Unfortunately, unchecking this also broke my client’s search functionality as they had over 2000 posts we had to exclude from their search results, all in that one category.
Examining the code a bit further, it seemed something was probably amiss in wp-content/plugins/search-everything/search-everything.php around line 735:
// create the Categories exclusion query function se_build_exclude_categories() { global $wpdb; $excludeQuery = ''; if ( !empty( $this->query_instance->query_vars['s'] ) ) { $excludedCatList = trim( $this->options['se_exclude_categories_list'] ); if ( $excludedCatList != '' ) { $excluded_cat_list = array(); foreach(explode( ',', $excludedCatList ) as $cat_id) { $excluded_cat_list[] = (int)$cat_id; } $excl_list = implode( ',', $excluded_cat_list); if ( $this->wp_ver23 ) { $excludeQuery = " AND ( ctax.term_id NOT IN ( ".$excl_list." ) OR (wp_posts.post_type IN ( 'page' )))"; } else { $excludeQuery = ' AND (c.category_id NOT IN ( '.$excl_list.' ) OR (wp_posts.post_type IN ( \'page\' )))'; } } $this->se_log( "ex category where: ".$excludeQuery ); } return $excludeQuery; }
Glad to see that the developers have neatly laid out and commented the code, usually the sign of a decent plugin. I initially thought that escaping the apostrophes in the first reference to ‘page’ may work but it didn’t seem to. Here’s my temporary fix that works for my client until the developer can take a look:
// create the Categories exclusion query function se_build_exclude_categories() { global $wpdb; $excludeQuery = ''; if ( !empty( $this->query_instance->query_vars['s'] ) ) { $excludedCatList = trim( $this->options['se_exclude_categories_list'] ); if ( $excludedCatList != '' ) { $excluded_cat_list = array(); foreach(explode( ',', $excludedCatList ) as $cat_id) { $excluded_cat_list[] = (int)$cat_id; } $excl_list = implode( ',', $excluded_cat_list); if ( $this->wp_ver23 ) { $excludeQuery = " AND ( ctax.term_id NOT IN ( ".$excl_list." ))"; } else { $excludeQuery = ' AND (c.category_id NOT IN ( '.$excl_list.' ))'; } } $this->se_log( "ex category where: ".$excludeQuery ); } return $excludeQuery; }
If you are a bit unsure of messing with php files, do this:
- FTP into your server
- Copy search-everything.php to your PC (full path is wp-content/plugins/search-everything/search-everything.php)
- Open it in a text editor such as Notepad (or better still the free and excellent Notepad++) and modify the code to read as above
- Rename search-everything.php on your server to search-everythingORIG.php
- Upload the search-everything.php file from your PC to the server in the same location as it was.
- Test and do the happy dance if it works
If you do apply this, don’t forget to keep an eye out for the bugfix from the plugin developers.
Hope it works for you!