{"id":388,"date":"2014-07-06T03:13:28","date_gmt":"2014-07-06T03:13:28","guid":{"rendered":"https:\/\/digitalchild.info\/?p=388"},"modified":"2014-07-06T03:13:28","modified_gmt":"2014-07-06T03:13:28","slug":"buddypress-wordpress-search","status":"publish","type":"post","link":"https:\/\/randomadult.local\/buddypress-wordpress-search\/","title":{"rendered":"BuddyPress and WordPress Search"},"content":{"rendered":"

I had a\u00a0site that needed private messaging so I decided to use\u00a0BuddyPress as it already has a great messaging system. It appeared to\u00a0work\u00a0well with all the existing plugins until I tried to use the site search. I use\u00a0Facetious Search<\/a> 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\u00a0would redirect to the base site URL. Disabling either plugin would result in\u00a0search working again.\u00a0This is what I had to do to get\u00a0Buddypress and WordPress search working again.<\/p>\n

After going line by line through Facetious I discovered that if I disabled the nice\u00a0URLs 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.<\/p>\n

\n\n$this->search_base = apply_filters( 'facetious_search_base', $wp_rewrite->search_base );\n\n<\/pre>\n

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. \u00a0This meant that when Facetious tries to rewrite nice URLs BuddyPress would take over the search and redirect to the home page.<\/p>\n

I found the section\u00a0of 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.<\/p>\n

\n\n\/\/ The search slug has to be defined nice and early because of the way\n\/\/ search requests are loaded\n\/\/\n\/\/ @todo Make this better\nif ( !defined( 'BP_SEARCH_SLUG' ) )\ndefine( 'BP_SEARCH_SLUG', 'search' );\n\n<\/pre>\n

I found it ironic that they have the ‘make this better’ as it takes over search. I tried various things\u00a0trying 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.<\/p>\n

Update<\/strong>: I posted my problem over on the BuddyPress forums <\/a>and\u00a0I got a response from\u00a0Henry 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.<\/p>\n

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.<\/del><\/p>\n

\ndefine( 'BP_SEARCH_SLUG', 'searchresults' );\n\n<\/pre>\n

What this does is defines BuddyPress’s search slug to not be the same as the WordPress\u00a0or facetious search slug. I’m not sure if this is the best way to do this but it works.<\/p>\n

Update: Here is the github issue<\/a> from Facetious search that I raised then worked through to find the answer.<\/p>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

I had a\u00a0site that needed private messaging so I decided to use\u00a0BuddyPress as it already has a great messaging system. It appeared to\u00a0work\u00a0well with all the existing plugins until I tried to use the site search. I use\u00a0Facetious Search which is a really nice search plugin for WordPress. I have …<\/p>\n

BuddyPress and WordPress Search<\/span> Read More \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[5],"tags":[29,174,224],"yoast_head":"\nBuddyPress and Wordpress Search<\/title>\n<meta name=\"description\" content=\"I had a problem with Buddypress and Wordpress search not working. This was due to an issue with re-writes and how BuddyPress takes over search.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/randomadult.local\/buddypress-wordpress-search\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"BuddyPress and Wordpress Search\" \/>\n<meta property=\"og:description\" content=\"I had a problem with Buddypress and Wordpress search not working. This was due to an issue with re-writes and how BuddyPress takes over search.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/randomadult.local\/buddypress-wordpress-search\/\" \/>\n<meta property=\"og:site_name\" content=\"Random Adult\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-06T03:13:28+00:00\" \/>\n<meta name=\"author\" content=\"digitalchild\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dcwhatwhat\" \/>\n<meta name=\"twitter:site\" content=\"@dcwhatwhat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"digitalchild\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/randomadult.local\/buddypress-wordpress-search\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/randomadult.local\/buddypress-wordpress-search\/\"},\"author\":{\"name\":\"digitalchild\",\"@id\":\"https:\/\/randomadult.local\/#\/schema\/person\/b0b954202434291ace51b4e7a0a81c04\"},\"headline\":\"BuddyPress and WordPress Search\",\"datePublished\":\"2014-07-06T03:13:28+00:00\",\"dateModified\":\"2014-07-06T03:13:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/randomadult.local\/buddypress-wordpress-search\/\"},\"wordCount\":535,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/randomadult.local\/#organization\"},\"keywords\":[\"buddypress\",\"search\",\"wordpress\"],\"articleSection\":[\"Geek\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/randomadult.local\/buddypress-wordpress-search\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/randomadult.local\/buddypress-wordpress-search\/\",\"url\":\"https:\/\/randomadult.local\/buddypress-wordpress-search\/\",\"name\":\"BuddyPress and Wordpress Search\",\"isPartOf\":{\"@id\":\"https:\/\/randomadult.local\/#website\"},\"datePublished\":\"2014-07-06T03:13:28+00:00\",\"dateModified\":\"2014-07-06T03:13:28+00:00\",\"description\":\"I had a problem with Buddypress and Wordpress search not working. This was due to an issue with re-writes and how BuddyPress takes over search.\",\"breadcrumb\":{\"@id\":\"https:\/\/randomadult.local\/buddypress-wordpress-search\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/randomadult.local\/buddypress-wordpress-search\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/randomadult.local\/buddypress-wordpress-search\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/randomadult.local\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"BuddyPress and WordPress Search\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/randomadult.local\/#website\",\"url\":\"https:\/\/randomadult.local\/\",\"name\":\"Random Adult\",\"description\":\"Ramblings of a random adult\",\"publisher\":{\"@id\":\"https:\/\/randomadult.local\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/randomadult.local\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/randomadult.local\/#organization\",\"name\":\"Random Adult\",\"url\":\"https:\/\/randomadult.local\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/randomadult.local\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/logo.png\",\"contentUrl\":\"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/logo.png\",\"width\":320,\"height\":134,\"caption\":\"Random Adult\"},\"image\":{\"@id\":\"https:\/\/randomadult.local\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/twitter.com\/dcwhatwhat\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/randomadult.local\/#\/schema\/person\/b0b954202434291ace51b4e7a0a81c04\",\"name\":\"digitalchild\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/randomadult.local\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e0331079f6730910bc7760cb8f781237?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e0331079f6730910bc7760cb8f781237?s=96&d=mm&r=g\",\"caption\":\"digitalchild\"},\"url\":\"https:\/\/randomadult.local\/author\/digitalchild\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"BuddyPress and Wordpress Search","description":"I had a problem with Buddypress and Wordpress search not working. This was due to an issue with re-writes and how BuddyPress takes over search.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/randomadult.local\/buddypress-wordpress-search\/","og_locale":"en_US","og_type":"article","og_title":"BuddyPress and Wordpress Search","og_description":"I had a problem with Buddypress and Wordpress search not working. This was due to an issue with re-writes and how BuddyPress takes over search.","og_url":"https:\/\/randomadult.local\/buddypress-wordpress-search\/","og_site_name":"Random Adult","article_published_time":"2014-07-06T03:13:28+00:00","author":"digitalchild","twitter_card":"summary_large_image","twitter_creator":"@dcwhatwhat","twitter_site":"@dcwhatwhat","twitter_misc":{"Written by":"digitalchild","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/randomadult.local\/buddypress-wordpress-search\/#article","isPartOf":{"@id":"https:\/\/randomadult.local\/buddypress-wordpress-search\/"},"author":{"name":"digitalchild","@id":"https:\/\/randomadult.local\/#\/schema\/person\/b0b954202434291ace51b4e7a0a81c04"},"headline":"BuddyPress and WordPress Search","datePublished":"2014-07-06T03:13:28+00:00","dateModified":"2014-07-06T03:13:28+00:00","mainEntityOfPage":{"@id":"https:\/\/randomadult.local\/buddypress-wordpress-search\/"},"wordCount":535,"commentCount":0,"publisher":{"@id":"https:\/\/randomadult.local\/#organization"},"keywords":["buddypress","search","wordpress"],"articleSection":["Geek"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/randomadult.local\/buddypress-wordpress-search\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/randomadult.local\/buddypress-wordpress-search\/","url":"https:\/\/randomadult.local\/buddypress-wordpress-search\/","name":"BuddyPress and Wordpress Search","isPartOf":{"@id":"https:\/\/randomadult.local\/#website"},"datePublished":"2014-07-06T03:13:28+00:00","dateModified":"2014-07-06T03:13:28+00:00","description":"I had a problem with Buddypress and Wordpress search not working. This was due to an issue with re-writes and how BuddyPress takes over search.","breadcrumb":{"@id":"https:\/\/randomadult.local\/buddypress-wordpress-search\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/randomadult.local\/buddypress-wordpress-search\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/randomadult.local\/buddypress-wordpress-search\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/randomadult.local\/"},{"@type":"ListItem","position":2,"name":"BuddyPress and WordPress Search"}]},{"@type":"WebSite","@id":"https:\/\/randomadult.local\/#website","url":"https:\/\/randomadult.local\/","name":"Random Adult","description":"Ramblings of a random adult","publisher":{"@id":"https:\/\/randomadult.local\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/randomadult.local\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/randomadult.local\/#organization","name":"Random Adult","url":"https:\/\/randomadult.local\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/randomadult.local\/#\/schema\/logo\/image\/","url":"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/logo.png","contentUrl":"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/logo.png","width":320,"height":134,"caption":"Random Adult"},"image":{"@id":"https:\/\/randomadult.local\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/twitter.com\/dcwhatwhat"]},{"@type":"Person","@id":"https:\/\/randomadult.local\/#\/schema\/person\/b0b954202434291ace51b4e7a0a81c04","name":"digitalchild","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/randomadult.local\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e0331079f6730910bc7760cb8f781237?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e0331079f6730910bc7760cb8f781237?s=96&d=mm&r=g","caption":"digitalchild"},"url":"https:\/\/randomadult.local\/author\/digitalchild\/"}]}},"_links":{"self":[{"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/posts\/388"}],"collection":[{"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/comments?post=388"}],"version-history":[{"count":0,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/posts\/388\/revisions"}],"wp:attachment":[{"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/media?parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/categories?post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/tags?post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}