I had a site that needed private messaging so I decided to use BuddyPress as it already has a great messaging system. It appeared to work well with all the existing plugins until I tried to use the site search. I use Facetious Search which is a really nice search plugin for WordPress. I have custom post types and a bunch of extra custom fields that I would like to search and Facetious makes that really easy. The only problem is that if you have both BuddyPress and Facetious Search installed, search stops working all together. No matter whether I used the built-in search or the Facetious widgets, any query would redirect to the base site URL. Disabling either plugin would result in search working again. This is what I had to do to get Buddypress and WordPress search working again.
After going line by line through Facetious I discovered that if I disabled the nice URLs in the plugin search started working again. I went through all the nice URL code and found that line 273 of facetious.php was where search would stop working.
$this->search_base = apply_filters( 'facetious_search_base', $wp_rewrite->search_base );
I tried to see if I could override this somehow but it wasn’t doing anything out of the ordinary. I started digging around BuddyPress and discovered that it likes to take over WordPress search. This meant that when Facetious tries to rewrite nice URLs BuddyPress would take over the search and redirect to the home page.
I found the section of code that was the culprit in the BuddyPress source code in bp-loader.php. In version 2.0.1 of BuddyPress it starts at line 284 of the bp-loader.php.
// The search slug has to be defined nice and early because of the way // search requests are loaded // // @todo Make this better if ( !defined( 'BP_SEARCH_SLUG' ) ) define( 'BP_SEARCH_SLUG', 'search' );
I found it ironic that they have the ‘make this better’ as it takes over search. I tried various things trying to override this constant and I couldn’t get anything to work as it loads it too early for me to have the override in my theme.
Update: I posted my problem over on the BuddyPress forums and I got a response from Henry Wright suggesting I put this into a bp-custom.php file. I had attempted this before but for some reason it wasn’t working, It does now. This file is used to create customisations to BuddyPress and I’m already using this which is located in the plugins directory.
The only way I could get this to work was to define the constant in the WordPress config. Adding the following to your wp-config.php will allow both plugins to play nicely.
define( 'BP_SEARCH_SLUG', 'searchresults' );
What this does is defines BuddyPress’s search slug to not be the same as the WordPress or facetious search slug. I’m not sure if this is the best way to do this but it works.
Update: Here is the github issue from Facetious search that I raised then worked through to find the answer.