BuddyDev

BuddyPress Global/Sitewide Unified search update for BuddyPress 1.5+

It's a delayed post and I will like to express my sincere apologies to everyone whom I could not reply individually about the Unified Search. Here I am going to put everything you ever asked about unified search in this post.
For those of you who haven't seen my last post please check the original post here. This post is all about making unifiead search work with BuddyPress 1.5+. It is a long post, so please  have a cup of coffee and let us get started.

List of things we will cover below:-

Lets get started now.

Step1:- Installing the BP Global Unified search plugin

Install BP Global Unified search plugin.

Download:-BP Global Unified search

Once you Install and activate this plugin, BuddyPress will give you a notice that you need to create a page and associate it with Search Page.
Here is a screenshot showing the notice

Please create a WordPress page and associate the page with search page component in BuddyPress->Pages screen.
If you are done with this, let us proceed to the coding part now.

Please note that all the code below should go to your active theme/functions.php until and unless mentioned.

Step2:- Basic setup for theme

Remove the BuddyPress dropwn filters for members/groups/posts etc

[sourcecode language="php"]
//Remove Buddypress search drowpdown for selecting members etc
add_filter('bp_search_form_type_select', 'bpmag_remove_search_dropdown' );
function bpmag_remove_search_dropdown($select_html){
return ";
}
[/sourcecode]

Step 3: Fixing the redirect/page not found for search page

Stop BuddyPress from redirecting to members/other component(by default on search, you are redirected to members directory). Let us stop that behavior.

[sourcecode language="php"]
//force buddypress to not process the search/redirect
remove_action( 'bp_init', 'bp_core_action_search_site', 7 );
[/sourcecode]

Step4: Now, let us handle the search page ourself

[sourcecode language="php"]
//let us handle the unified page ourself
add_action( 'init', 'bp_buddydev_search', 10 );// custom handler for the search
function bp_buddydev_search(){
global $bp;
if ( bp_is_current_component(BP_SEARCH_SLUG) )//if thids is search page
bp_core_load_template( apply_filters( 'bp_core_template_search_template', 'search-single' ) );//load the single searh template
}
[/sourcecode]

Step5: Tweaking the Query string for search

We will append the search term to BuddyPress query string.

[sourcecode language="php"]
add_action('advance-search','bpmag_show_search_results',1);//highest priority
/* we just need to filter the query and change search_term=The search text*/
function bpmag_show_search_results(){
//filter the ajaxquerystring
add_filter('bp_ajax_querystring','bpmag_global_search_qs',100,2);
}

//modify the query string with the search term
function bpmag_global_search_qs(){
return 'search_terms='.$_REQUEST['search-terms'];
}

//a utility function
function bpmag_is_advance_search(){
global $bp;
if(bp_is_current_component( BP_SEARCH_SLUG))
return true;
return false;
}

[/sourcecode]

Now we are done with the basic setup. It is time to show the search reults.

Step 6: Create a search-single.php in your theme

In the content area(if you are using default theme, then inside the div "padder") put the following line

[sourcecode language="php"]
<?php do_action("advance-search");?>
[/sourcecode]

Step7: showing the results

It is time to show the results. Please note, you can change which component's search is shown first by changing the priority in the add_action below. Basically, we will check for the active component and just add their search result using the add_action, let us start with members.

Members search

[sourcecode language="php"]
//show the search results for member*/
function bpmag_show_member_search(){
?>
<div class="members-search-result search-result">
<h2 class="content-title"><?php _e('Members Results',"bpmag");?></h2>
<?php locate_template( array( 'members/members-loop.php' ), true ) ; ?>
<?php global $members_template;
if($members_template->total_member_count>1):?>
<a href="<?php echo bp_get_root_domain().'/'. bp_get_members_slug().'/?s='.$_REQUEST['search-terms']?>" ><?php _e(sprintf('View all %d matched Members',$members_template->total_member_count),"bpmag");?></a>
<?php endif; ?>
</div>
<?php
}
//Hook Member results to search page
add_action('advance-search','bpmag_show_member_search',10); //the priority defines where in page this result will show up(the order of member search in other searchs)

[/sourcecode]

Similarly, we will add the support for other components.

Adding Group Search

[sourcecode language="php"]

//Group search
function bpmag_show_groups_search(){
?>
<div class="groups-search-result search-result">
<h2 class="content-title"><?php _e('Group Search','bpmag');?></h2>
<?php locate_template( array('groups/groups-loop.php' ), true ) ; ?>

<a href="<?php echo bp_get_root_domain().'/'. bp_get_groups_slug().'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Groups","bpmag");?></a>
</div>
<?php
//endif;
}

//Hook Groups results to search page
if(bp_is_active( 'groups' ))
add_action('advance-search','bpmag_show_groups_search',15);
[/sourcecode]

Searching Activity Updates

[sourcecode language="php"]

/**activity update search*/
//Activity search
function bpmag_show_activity_search(){
?>
<div class="activity-search-result search-result">
<h2 class="content-title"><?php _e('Activity Updates','bpmag');?></h2>
<?php locate_template( array('activity/activity-loop.php' ), true ) ; ?>

<a href="<?php echo bp_get_root_domain().'/'. bp_get_activity_slug().'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View all matched updates","bpmag");?></a>
</div>
<?php
//endif;
}

//Hook Activity results to search page
if(bp_is_active( 'activity' ))
add_action('advance-search','bpmag_show_activity_search',20);
[/sourcecode]

Showing Blog post search

[sourcecode language="php"]

/**
*
* Show blog posts in search
*/
function bpmag_show_site_blog_search(){
?>
<div class="blog-search-result search-result">

<h2 class="content-title"><?php _e('Blog Search','bpmag');?></h2>

<?php locate_template( array( 'search-loop.php' ), true ) ; ?>
<a href="<?php echo bp_get_root_domain().'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Posts","bpmag");?></a>
</div>
<?php
}

//Hook Blog Post results to search page
add_action('advance-search',"bpmag_show_site_blog_search",25);
[/sourcecode]

Showing Blogs search(for Multisite)

[sourcecode language="php"]
//show blogs search result

function bpmag_show_blogs_search(){

?>
<div class="blogs-search-result search-result">
<h2 class="content-title"><?php _e('Blogs Search',"bpmag");?></h2>
<?php locate_template( array( 'blogs/blogs-loop.php' ), true ) ; ?>
<a href="<?php echo bp_get_root_domain().'/'. bp_get_blogs_slug().'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Blogs","bpmag");?></a>
</div>
<?php
}

//Hook Blogs results to search page if blogs comonent is active
if(bp_is_active( 'blogs' ))
add_action('advance-search','bpmag_show_blogs_search',30);

[/sourcecode]

Showing Forum(the Groups forum) topics in the search

[sourcecode language="php"]

//show forums search
function bpmag_show_forums_search(){
?>
<div class="forums-search-result search-result">
<h2 class="content-title"><?php _e("Forums Search","bpmag");?></h2>
<?php locate_template( array( 'forums/forums-loop.php' ), true ) ; ?>
<a href="<?php echo bp_get_root_domain().'/'. bp_get_forums_slug().'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched forum posts","bpmag");?></a>
</div>
<?php
}

//Hook Forums results to search page
if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() && bp_forums_has_directory() )
add_action('advance-search',"bpmag_show_forums_search",35);

[/sourcecode]

Extra bonus for following this tutorial till now:-
Showing Results for BBPress 2.0 plugin

[sourcecode language="php"]
function bpmag_show_bbpress_topic_search(){
$_REQUEST['ts']=$_REQUEST['search-terms'];//put it for bbpress topic search
?>
<div class="bbp-topic-search-result search-result">
<h2 class="content-title"><?php _e('Global Topic Search',"bpmag");?></h2>
<?php bbp_get_template_part('bbpress/content','archive-topic') ; ?>
<?php
global $bbp;
$page = bbp_get_page_by_path( $bbp->root_slug );

?>
<a href="<?php echo get_permalink($page).'?ts='.$_REQUEST['search-terms']?>" ><?php _e("View All matched topics","bpmag");?></a>
</div>
<?php
}

//Hook Blogs results to search page if blogs comonent is active
if(function_exists( 'bbp_has_topics' ))
add_action('advance-search','bpmag_show_bbpress_topic_search',40);

[/sourcecode]

btw, if you find this tutorial a long one, you can simply copy the template/functions.php from bp-global-unified-search and paste it in your theme's functions.php. Also, I have put a sample search-loop.php in the bp-global-unified-search/template directory. So, you can use it directly or adapt to your theme.

I hope you will like it. Looking forward to hear your suggestions and feedback for further improvement.

177 Responses to BuddyPress Global/Sitewide Unified search update for BuddyPress 1.5+

  • This is awesome @sbrajesh !! thank you. First quick attempt it didn't work but I didn't expect it to as my theme is highly custom. I hope to get this working though as it would be much appreciated by my members.

    • Hi Jeremy,
      Thank you for the comment. You may try by copying the code from template/functions.php. That may be easier for you. hope that helps 🙂

  • Ty very much! Working like a charm in bp_default_theme in BP 1.5!

    • thank you for the comment and confirming. Appreciate it 🙂

  • Yujuuuuuuu! thank you!

  • Hey! great plugin! just two questions:

    1) Could it be possible to also search within comments of activities?
    2) Could it be possible to search also for the usernames? (@username instead of only the name given at registration)

    Thank you very much and keep up the excellent job!

    • Hi Abyss
      Thanks for the comment.
      1. Most probably yes. I am using buddypress's search functionality for activity and I believe it does search that
      2. No, buddypresws does not look for username, It looks for the user's full name.

      Hope that helps.

  • Thanks for your answer 🙂

    Regarding point 1, I followed all the steps in the how-to but it's not searching comments, only activities. Are you sure you're getting results from the comments ?

    Thanks !

    • Thanks for this one, it is great!
      Like Abyss, I would like to be able to search in comments … or having tags in bp-gallery.
      I'm using Buddypress as an extension of a classroom and it is really time consuming to search within the content of my site, especially for specific photos.

      • Hi Abyss, Claude,
        sorry for my late reply. Checked with Bp 1.5.3.1 and found that the search (activity search) does not filter comments at the moment. will take a deeper look in a week or two and will let you know.

  • Hi Brajesh. Many thanks as usual 🙂

  • Damn! I can't seem to get this up and running! I remember that months ago I got it working with bp-default and Buddypress1.5 but now using WP3.3 + latest bbPress trunk (2.1) and latest Buddypress trunk (1.6) it doesn't work. The search dropdown is removed correctly. But whatever I type in there -> only members are searched. The other hooks don't seem to work. Maybe it's an issue on my side as I am using a child-theme of bp-default?

    • btw. the search is always performed on the "members page". I even can't see any new search template like you have in your screenshot.

      • Hi,
        I haven't tested it on BuddyPress 1.6 branch. will do tonight.

        Most probably the problem seems to be related to the removing of 'bp_core_action_search_site' action. It seems it is not getting removed properly on 1.6.

        • Hi Brajesh, did you have a chance to look into this yet? I am having the exact same issue as vatoloco where the search is only performed on the "Members Page". Thanks very much for your hard work on this and looking forward to hearing your thoughts.

        • Hi,
          sorry for delayed reply.
          I just tested it on wpms 3.3 and BuddyPress 1.6(rev 5634) and It is working fine for me.

          Please make sure you have create the search page and associated in the BuddyPress pages area.

  • Hi Brajesh,

    Thanks again for sharing your code, always really usefull.
    Do you have an idea how to modify the Member search loop to look for username instead of "Nice Name".
    Thx
    s

    • Hi Salocin,
      sorry but the BuddyPress search loop(for members) does not support searching by username at the moment.

  • Is there a way to add the URL as one of the pieces of content the "Blogs" search looks for. Currently it sees the Title of the blog, but not the subdomain text.

    • Hi,
      I am sorry I missed to reply earlier.
      Since we are using the BuddyPress blogs-loop from blogs directory, the search output depends on how the blog-loops.php is laid out. I believe, the current buddypress blogs search does not allow searching on the basis of subdomain/sub dir name.

  • Hi,

    I just followed the instructions listed here and I'm seeing a completely blank page (no layout, just white) when I try to visit the new search page I created.

    I created the new search page, assigned it to "Search page" in my admin, copied your template files and all the rest…not sure whats going wrong. Any ideas?

    Thanks in advance

    • Hi David,
      Please make sure you have a search-single.php in your current theme. That file is required for the search result page.

  • Hi Brajesh,

    I am using BuddyPress 1.5.3.1 and have added the your integrated search bar. It will return authors, but doens't seem to want to return any results from posts, or from the (one) forum that I have set up. Any ideas on where I should start looking for causes?

  • Hi Brajesh,

    I was using unified search on a 1.3 Buddypress install and it worked perfectly.
    Recently upgraded to latest BP1.5 and adapted the code as above.

    I checked everything, but when performing a search, I am getting a Page not Found.
    I have created a search page
    I have set it up in the Buddypress/Pages option
    I have a search-single.php

    Any ideas?
    thx
    s

  • Found my own answer.
    In wp-config I had teh search slug already defined (to find instead of search)
    So just needed to update
    define ( 'BP_SEARCH_SLUG', 'search' );

  • Could I pay someone to help me install this search?

    //Remove Buddypress search dropdown for selecting members etc add_filter('bp_search_form_type_select', 'bpmag_remove_search_dropdown' ); function bpmag_remove_search_dropdown($select_html){ return "; } //force buddypress to not process the search/redirect remove_action( 'bp_init', 'bp_core_action_search_site', 7 ); //let us handle the unified page ourself add_action( 'init', 'bp_buddydev_search', 10 );// custom handler for the search function bp_buddydev_search(){ global $bp; if ( bp_is_current_component(BP_SEARCH_SLUG) )//if thids is search page bp_core_load_template( apply_filters( 'bp_core_template_search_template', 'search-single' ) );//load the single searh template }
    Warning: Cannot modify header information – headers already sent by (output started at /home/atlanta/www/www/wp-content/themes/parallelus-salutation/gallery/functions.php:176) in /home/atlanta/www/www/wp-admin/theme-editor.php on line 103

    • Hi Diane,
      sorry for my late reply.

      It seems you have spaces left either before the opening php tag or after the closing php tag. Please remove that and the error will go away.

  • Hi Brajesh,

    I'm using a custom theme that uses to show the search form. But it keeps sending the query to /?s=query&submit=Search

    If I change the URL to /search?s= it works ok.

    I've added define ( ‘BP_SEARCH_SLUG’, ‘search’ ); to bp-custom.php but it makes no difference.

    Could you give me a hand 🙂
    Thanks !

    • I ment, my theme uses: get_search_form(); to show the search box

    • Hi Abyss,
      is your themes search box compatible with BuddyPress(I mean does it offer the members/groups etc drop down?).
      Also, please do not forget to put
      [sourcecode language="php"]
      remove_action( 'bp_init', 'bp_core_action_search_site', 7 );
      [/sourcecode]
      in your functions.php

  • Bump.. not sure why my comment is in moderation.

    • Tee #

      Hi Brajesh,

      It seems I Have the same problem. I do have a search results page listing all results. But it is not connected to my WordPress Search Form. And the link /search?s=Searchterm leads to the right page but again doesn't seem to have any effect.

      I suspect, my themes search box isn't compatible with BuddyPress. it does not offer the members/groups etc drop down. How can I add that function. Thanks, T

  • Hi again,

    I see that I didn't have the search-loop file in my child theme – that was stopping blog listings from showing up. I didn't see an instruction to add that – maybe I'm missing where that instruction goes. Thanks for this – I'm going to start to try and customize it now.

  • Hi Andrew,
    sorry If I missed to point it. For searching posts, we will need a search-loop.php in our parent theme or child theme.

    regards
    Brajesh

  • Hi Brajesh, thanks again !

    I used the line you referred to :/

    I think it doesn't support BP. I have added it myself since the default configuration didn't have a search box (it does have a member search). Should I see how's that searchbox handled ?

    Thanks !

    • Hi Abyss,
      Please post the search form code on pastebin and I will update that for you 🙂

  • Brajesh, thanks so much !

    http://pastebin.com/c9bhpWt3

    In there you will find both the member search and the search box I added.
    Thanks again 😀

  • Quick question – should my blog post search results be showing the excerpts, and then the full posts? I get excerpt1, excerpt2, excerpt3, and then fullpost1, fullpost2 fullpost3.

    Thanks.

    Thanks for the get_search_form replacement code too!

  • Hey ! it's getting there but not working yet :/

    Now the page goes to /search but doesn't pass any argument, just plain "/search" if I mannually add "?s=hello" it works but it's not sending it by default 🙁

    Thanks again !

  • I've recently set this up and have been able to create a page which gives me the search results for members, groups, activity updates and blog posts.

    However it will not return results for forum threads.

    I notice that if I go into functions.php and change:

    if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() && bp_forums_has_directory() )
    add_action('advance-search',"bpmag_show_forums_search",35);

    To:

    //if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() && bp_forums_has_directory() )
    add_action('advance-search',"bpmag_show_forums_search",35);

    (i.e. comment out the first line)

    This now works. Presumably my site is failing one of the checks made in the code to check everything is installed properly – I'm not sure why that is because my forums are all set up and working fine.

  • One of the oddities I've noticed with the new version of this is that the page you have to create for the search results itself now shows up in the list of results for blog posts. Can this be fixed?

  • If I might suggest another area for improvement: At present, if your search for blog posts, forum threads or groups yields no results, you still get the option to "view all matched blog posts", etc…

    Ideally this should not happen, as is the case if your search for members yields no results.

    I should add that I think the plugin is excellent and works very well – I only suggest these changes in the hope that it can be made even better!

  • Finally got this semi-working… Only issue is that the results page has a messed up list of the admin bar links down the left side of the page and I don't have the admin bar active on my site. How can I fix this admin bar links glitch?

  • This plugin is great! Life saver really. My only question is how I would prevent Admins, Editors, etc from being searched. With the site I am building, I would only want Subscribers to be found. Or if I need to block specific users from being found, that would work too since there are only a handful. Thanks in advance!

  • Hi great plugin, after you perform a search, the results come up perfect, but if you try to hit the reply or favorite button, they fail. Do you know any work around for this?

    Thank you,

    • I am experiencing the same issue with the favorite and comment buttons in the search results. Any fix for this? If not, is there a temporary "if search" code I could wrap around the meta area in my post so that if its listed in the search results it will only display the view permalink for each post?

      • Hi Spade, Chris,
        Please change the class of wrapper div of activity search from 'activity-search-result search-result' to 'activity-search-result search-result activity' and It should allow replying/Favoriting.

        • Hi Brajesh, that worked great for the replying! thanks again, but for some reason the favoriting is not working. It seems to be displaying the entire site over and over again next to the favorite button, like in a loop.

        • Thanks for your time, but like Chris said, The comment section now works but the favoriting causes it to show my entire site as if it were in an iframe listed right under the post I favorited. I also notices the load more button does not work at all.

  • Thanks very much for this plugin — works great.

    It would be great if "Results for search term[s]: [search term] were displayed at the top when results are returned. There currently seems to be no indication when viewing results what the search term(s) was. If not the message at the top, then perhaps the term/s could be bolded in the results?

    +1 for Notpoppy's suggestion: "View all matched __" should display only if there are results for that component.

    I also had to use Notpoppy's tip on commenting out the line for forums. I use your Global Forums plugin and get results only if I comment out the conditional. Is there another "if active" statement I can use for Global Forums?

    Thanks again!

    • Hi King,
      Thank you for the comment.
      I will update it to show the View all only if have more than the displayed results. It was just some lazy work on my end.

      The global forum search will not work on the search page if group forum is enabled. Please do let me know if you have disabled group forum or using it ?

      • I'm not 100% sure I know what you mean by "group forum" but I think the answer in any case is that group forum is enabled because my groups do have a forum component and my global forums page does include a list of forums that correspond to groups.

        So if it is the case that group forum is enabled on my site, I'm also not sure why you say that global forum search will not work. It's working just fine for me, once I took Notpoppy's suggestion to comment out the conditional is_active line in your code to hook forums results to search page.

        But while everything seems to be working great, I was just wondering whether I really should replace the conditional is_active code with something else that plays nice with your global forums plugin rather than just commenting out that code.

        I hope that makes sense.

  • I found out how to echo the search term at the top of the search results — just copied and modified the 404/'no results' code at the bottom of search-loop.php, which had the %s search term variable I was looking for. Pretty simple.

  • Hi Brajesh, I noticed the search doesn't like apostrophes. Searching for "Dano's" for instance produces no results even though it's the name of a member but searching for Danos does find the member. The apostrophe results say "no results for dano\'s". I tried other punctuation for kicks and they all searched fine. When searching members I think an apostrophe is somewhat common. Thanks in advance.

    • Hi Greg,
      Thank you for the comment.

      Just tested and you are right about the issue.

      But on checking further, I just found that this is the way BuddyPress search works. This is not a problem with unified search rather BuddyPress does not like apostrophes in user searches and will not search if you put that in the member search.

  • very effective and useful solutions.

    It lacks a feature for my taste: the search for posts on a multisite BuddyPress, there looking for blogs, but not looking for blog posts in all blogs :/

    • Thank you for the comment.
      For searching the posts network wide, we will need to index all the posts. I don't see it happening at the moment and that's why the plugin is limited to current site posts.

  • Hi Brajesh,
    writing you just say thanks for the tutorial, share a problem somebody else may have and ask a question 🙂

    I'm experiencing problems clicking on Add friend button in the "SERP": an entire page appears close to the button. I fixed it adding exit(); at the end of function bp_dtheme_ajax_addremove_friend (similar solution for "show more" activities that didn't show).
    I read it in this article: http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#admin-ajax

    The lack of the exit function in default bp theme may be a bug?
    Thanks

    • HI Matteo,
      Thank you for the comment. It happens because up to bp 1.5.5, buddypress hooks to wp-load.php and does not need ext. If a plugin overrides the ajaxurl with admin-ajax then the problem arises. This is fixed in the BuddyPress 1.6 trunk and so will I update the plugin when it comes out :

  • Hi,

    Thanks for a great plugin. (BP is in need of something like this in core i think).

    Couple of issues however:

    1) My site loads some javascript to control main menu's, BUT your plugin removes/disables this js on the search results page.

    2) when using on MOBILE devices (Nokia/Opera) none of the links in search results work (though they are formed correctly in html, clicking them just returns to the search results page) – very strange.

    Any ideas?

    Many thanks.

    • Hi Rob,
      thank you for the comment.
      1. are you using any conditionals? I am not sure why this plugin will remove that. Can you post some sample code you are using to hook the javascript. Maybe, I can have better idea then.
      2. No, I haven't seen that behavior? Can you confirm if that happens when bp-default theme is active ?

  • Hi Brajesh,
    Thanks for the reply. I'll do some more testing/tracing over the next few days and post you what I find. Very best regards.

  • Hello Brajesh!!! I was really looking for this plugin for a long time and I finally found it. But there's a problem: When I installed it, it seems that the results totally ignore the site's alignments! Why is that? Do you know how can I fix that?
    Pleasem any help would be appreciated!!
    Thanks.

    BTW: The site is http://laresdj.com and the search bar is in the upper right side of the header! 😉

    • Hi LaresDJ,
      thank you for the comment.
      You will need add this selector on line 114 in your style.css(In your theme, you have amny selector there, just append it after comma).
      body.search div#container

      That will fix it.

      • If my code is something like this:

        body.activation div#container,
        body.search-results div#container,
        body.search-no-results div#container {

        Where do I insert the "body.search div#container" code?
        Thanks for your time Brajesh!

        • Hi,
          you can put it like this

          body.activation div#container,
          body.search-results div#container,
          body.search-no-results div#container,
          body.search div#container {

          That will do it.

      • Thanks my friend!!! It fixed the left margin but the right one is still collapsed within the right column!! :S
        If you know how to fix this, I would really RE-appreciate it! 😉
        Thanks

  • Rather than comment out the line completely, it may be worth having at least some basic checking. I've cut my forums condition check back to:
    if ( bp_is_active( 'forums' ) && bp_is_active( 'groups' ) )
    add_action('advance-search',"bpmag_show_forums_search",20);

    If for some reason a BuddyPress install is not using groups that could also be removed from the if statement. The check for && bp_forums_is_installed_correctly() is not working for my install of BuddyPress 1.5.5 and with group forums configured.

    I concur with others above. A fantastic plugin. If the View all… messages could be suppressed when less than a few results appear, that would be totally awesome. Thanks again Brajesh, great job.

    • Thank you for the comment Veron.

      I am going to update this plugin soon when the bp 1.6 comes out and I do plan to fix the small tidbits including the view all message. Currently you can put a condition on total number found as I guess I have done in bpmag. 🙂

  • thanks again Brajesh! Do I understand correctly that if we add searching in activity loop, unified search returns activity results, but users won't be able to reply to those activities – meat will lead to the page refresh?

    Basically, question is whether is it possible to allow activity commenting on the search page?

    thank you!

    • sorry, cannot get how is it possible to type word "meat" in place of "it", probably, it's time for a lunch 🙂

      • I've been able to rename activity loop and modify it a bit to get commenting working. The only issue is that now, when I post comment to activity, ajax returns whole search page below the comment again.

  • thanks @Matteo , looks like it did the trick, the only thing to understand for me now is how this new exit() will affect BP?

  • @Matteo , do you know how to add exit(); without changes in core ajax.php of bp-default?

    • The function you want to modify should have something like add_action( 'wp_ajax_addremove_friend', 'bp_dtheme_ajax_addremove_friend' );

      Copy/paste the function (ie: bp_dtheme_ajax_addremove_friend) in your functions.php and modify it. Modify also the name (ie. bp_dtheme_ajax_addremove_friend_custom).

      Add

      remove_action( 'wp_ajax_addremove_friend', 'bp_dtheme_ajax_addremove_friend' );
      add_action( 'wp_ajax_addremove_friend', 'bp_dtheme_ajax_addremove_friend_custom' );

      …basically this replaces the core functions

  • Hi Brajesh Singh,

    regarding Step 6 of your tutorial which says: "Create a search-single.php in your theme". Do you mean the normal WP theme or the BuddyPress theme located in:

    /wp-content/plugins/buddypress/bp-themes/bp-default/

    if we use just the normal/default BuddyPress theme? And if the BuddyPress path is correct can/should we delete the "search.php" file which is already there & just copy in the "search-single.php" file from the template folder of your plugin?

    Just want make sure I have understood everything correctly before starting and many thanks for this awesome plugin. 😉

    • Oh nearly forget the second & most important question. Does your plugin supports a full text search of forum posts based on Groups? So that not only the titles of posts get listed but also the real content of posts?

      Thanks in advance.

      • As of your second question, This plugin uses buddypress forum search functionality and as far as I know, the functionality uses BB Query which should be fulltext.

    • Hi Rainer,
      sorry for the delayed reply.
      Which theme you are using. It should be in your currently active theme. If you are using the bp-default theme, then the path is correct. You don't need to delete the search.php. Just create a new file search-single.php and It will work.

  • Thanks a lot for your answers! 😉

  • Dear,

    Only on the search page, seems wp_head() is not working properly. I mean at least the header background image is missing. See below the missing code in the section.

    Note: I'm using the bp-default theme.

    Any hints ?

    Rgds,

    ====
    Missing code :

    #header { background-image: url(http://www.txy.fr/wp-content/uploads/2012/04/txy13.jpg); }
    #header h1, #header #desc { display: none; }

  • Following previous post,

    Changing line:
    add_action( 'init', 'bp_buddydev_search', 10 );// custom handler for the search
    To line:
    add_action( 'init', 'bp_buddydev_search', 9 );// custom handler for the search

    And the #header emit code is here ! Not sure to understand why :(.

    Rgds,

    • Hi Julie,
      Are you using custom headers? I am not sure why this search will prevent the site from loading the custom header.

  • No. I'm not using custom headers. I'm only setting up a background image to the default theme throught the setting panel.

    Rdds,

  • First thanks for great plugins & support.

    wp 3.4 has a search bar in the wp admin bar.

    It would be neat if buddypress-globalsitewide-unified-search could be functional off that search bar.

    Any guidance much appreciated

  • Basically a function to replace the search form in wp-includes/admin-bar.php with Brajesh's buddypress-globalsitewide-unified-search.

    Any ideas

    • Hi,
      I am putting an updated for BP 1.6 next week and will include your suggestions 🙂

  • Sam #

    Hello,

    Thank you sooo much for this tutorial, it is working great with me!

    Just one thing, the new buddypress got a new toolbar with search functionality, can you please tell us how can we add the new search to it? it still use the ?s= part which should be disabled already.

    Thanks again =)

  • Hi,
    I'm having a problem when inserting the code described in step 4. When it's inserted I get the following error on any page I want to open: Parse error: syntax error, unexpected T_STRING in /home/powerseurope.com/public_html/intranet/wp-content/themes/powers-europe-buddy/functions.php on line 16

    I'm using a Child Theme, WordPress 3.4.1 and BP 1.6
    Thanks in advance for the help.

  • following the update to 1.6.1 I am getting an error Call to undefined function bp_is_active() ——> related to the line if(bp_is_active( 'groups' ))

    this disable the entire site

    Any ideas ??

  • Hi Brajesh, I have yet to install your plugin, but I wish to thank you for making it available.

    Our site users need a search function that will search everything on the site, including WordPress blog category posts and Buddypress elements. Can your plugin search WordPress and Buddypress database tables?

    Thanks in advance,

    Eric

  • Hmm. I just can't seem to get this to work. No error output to report. Added the WP page, assigned it to BP at settings > buddypress > pages, added the code to functions.php, made a copy of search-single.php found in the unified plugin folder, pasted it into bp-default theme directory (leaving search.php that was in there untouched… is that ok?). The slug of my search page is /search/, but for some reason when I try to test this directly by going to mysite.com/search/ it will redirect to the homepage, retaining nothing in the URL, just a redirect home. I feel as though I've been meticulous about your steps, but clearly I'm missing something. Any ideas, suggestions?

  • You probably assumed this already, but yea I did of course install the plugin first (I simply forgot to mention it in earlier post)

  • Hello Brajesh Singh,
    thanks alot for this amazing Plugin.
    I am struggling to get it work on my page.
    Here is what I did so far. I downloaded, installed and activated the Plugin.
    Copied the search-loop.php and search-single.php to my theme folder.
    Copied the code from the functions.php to the end of my functions.php except the leading ""

    I am using BuddyPress Global Unified search Version 1.0.1
    BuddyPress 1.6.1
    Wordpress 3.4.2

    Any update for the Version 1.6 so far?

  • Hi Brajesh,

    I have a custom bp component, which was successfully added to your search using custom loop. Have one issue. For this component I need search to return results (posts titles from wp_posts) based on wp_postmeta query.
    Could you please tell if it is possible to modify your plugin somehow to fit my needs, or it can be solved from that custom loop only?

    thank you!

  • Pingback:PHP BuddyPress Search | Code Library

  • AWESOME & BRILLIANT!!! Thank you sooooo much! Works beautifully right out of the box.

  • Pingback:BuddyPress Site-wide Search – Global Unified Search Plugin | BulletProof Security Forum

  • Thank you!
    I'm no coder, but I followed your step-by-step instructions and it worked like a charm!

    Ciao from Italy! 🙂

  • Thank you for this very useful plugin and for these step-by-step instructions, it worked perfectly for me!
    I see that someone already asked about the possibility to search within comments to activity updates… are you planning to include this feature in any future update?
    Thanks again!

    • Hi Fabrizio,
      Thank you for the encouraging comments 🙂

      Currently, buddypress does not support activity comment search, let us hope it comes to the core in future and so we can utilize it 🙂

  • Sam #

    Does anyone know how to fix this?

    Parse error: syntax error, unexpected '}' in /home/u811427058/public_html/wp-content/themes/frisco-for-buddypress/search-single.php on line 15

  • Hi Sam,
    can you post your search-single.php on pastebin. It will help to find the reason.
    Thanks
    Brajesh

  • Hi There, I do like your plugin, however there seems to be an issue for me. When I search, it shows all the content (all activity, all members, etc.), as though it is not passing through any parameters. Do you know what could be the issue? Thanks.

    • Hi Katya,
      Which version of WordPress/BuddyPress you are using? and Is it multisite or standard wordpress?

      • Hi Brajesh, I am using wordpress 3.5 (the latest) and buddypress 1.6.2 (also the latest version).

        • Hi Katya,
          Just had a look at a fresh install of wp 3.5 and bp 1.6.2. It is working fine for me. It seems your form is not posting the search string to the search page. Can you please check if your search form is posting it correctly.

      • Sorry to ask, but what should I look for to know if the search form is posting it correctly? Could you explain this a bit more? Thanks!

      • Tee #

        Unfortunatly I have the same problem. It seems to work with groups, posts etc. But not with members, activities. Any Idea? Thanks!!

  • Don #

    Brajesh,

    I am looking forward to seeing your plugin work on my website, but I am having difficulty getting the search page to display. I created a Search page and 'repaired' the connections, but in the process I have ended up with a permalink labeled '…/search-2', but the software is looking for a page; '…/search'. Could this be causing my difficulty? How does the 'repair' binding work? Any suggestions for me?

    Thanks

    • Hi Don,
      Was testing it again and I am seeing some very strange behaviour of Unified search on my dev install. It is always redirecting to the search page(with slug search).

      I am looking into details and hoping to find the issue. Will post back again in the evening.

      Regards
      Brajesh

  • Hi All,
    Can you please give a try to global-unified-search 1.0.2.
    It will allow you to show the search results on non /search page too.

  • Is it possible to just show the blog search results on the results page instead of having a link to "View All matched Posts"?

    Thank you!

  • I need urgent help. I followed this tutorial and everything seems to be working fine except i want to include search results from only 3 categories (for blog posts).

    I tried to use this code in the search-loop.php file.

    I placed it like this:

    But it's not working. Can you please help?

  • Hi Brajesh, and thanks for this great plugin…

    Do you think there would be a way to modify it so that the group activity search can search among "sitewide hidden" activities (corresponding to hide_sitewide=1 in the database) provided the user is logged in, and is a member of the group ? As far as I can see, Buddypress Activity class is not designed to that purpose, and it would need filtering on bp_activity_get_user_join_filter to transform the query this way :

    SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name FROM wp_bp_activity a LEFT JOIN wp_users u ON a.user_id = u.ID WHERE (a.item_id IN (SELECT group_id
    FROM wp_bp_groups_members
    WHERE user_id =MYUSERID) OR a.hide_sitewide = 0 ) AND a.is_spam = 0 AND a.content LIKE '%%MYKEYWORD%%' AND a.type != 'activity_comment' ORDER BY a.date_recorded DESC LIMIT 0, 20

    I think I can do something like that, but it would be better to merge that into your plugin, what do you think?

    Bye,
    Yann

    • Hi Yann,
      Thank you for the comment. Though It is possible to do that viia passing another query string param show_hidden=1, It may expose other user's hidden activities too.

      I believe your code is good enough for the purpose. Just make sure to put a conditional to test you are doing it on global search page.

      • The issue with show_hidden is that it shows all hidden activities, even for group I'm not a member of, which would indeed be a bad behaviour… It could have done the job provided it had "none / mygroup / all" possible values, but not with only true/false values… :/ I gonna make a plugin. About the conditional test, do you mean using something like if(bpmag_is_advance_search())

  • hello, how can I exclude certain pages I want from the search using this code? please help me thanks

    • Hi Winny,

      You can check if you are on the search result page using this code

      bpmag_is_advance_search()

      and then you can use the pre_get_posts filter to exclude those pages.

  • My pagination is not working I guess… can I limit how many listing per search result output?

    • Hi Winny,
      Yes you can limit. If you are concerned about WordPress posts search, you will have to pass posts_per_page param, for BuddyPress, you can pass per_page param to control the no. of entries shown.

  • Hi Brajesh,

    Thank you for this very useful tutorial, I was looking for forums' search and didn't find something useful till I got here 🙂
    I took only the forums' search function and left the rest since it's already working in my theme.

    But I have 2 questions plz:
    1- How can I put the "Global Topic Search" results at the end of the page not at the top?
    2- How can we apply search to forums' replies too not just forums' topics?

    Thank you in advance
    Hope

    • Hi Hope,
      Thank you for the comment. sorry I could not reply earlier.
      Are you still looking for the solution ?

    • Having some issues with pagination of blog posts results as well. Could someone perhaps provide a working example?

  • Sorry .. Also how to hide "View All matched …." if no results were found?

    • Hi Brajesh,

      Thanks for replying. Actually I was working on other issues & postponed this one but yes I need a solution for it specially for the replies search.

      Your help is very appreciated..
      Thank you

      Hope

  • Hi Brajesh,

    this looks like it will be perfect for my needs but I can't quite get it working – this may be because my theme is quite heavily customised.

    When I type a search term into my search box it is using the "Wordpress" default search rather than the Buddypress one.

    I know the code is working because if I go to myurl / search it brings up a list of everything on my website.

    Any advice?

    thanks

    Dave

    • Hi Dave,
      Thank you for the comment.
      You will need to change the action of search form to this
      [sourcecode language="php"]
      <?php echo bp_search_form_action(); ?>
      [/sourcecode]

      Hope that helps

      • Hi Brajesh,

        that seems to have done the trick for getting the results on the right page – thanks very much that's a massive help!

        I do have a couple of follow up questions though:

        1. The members search seems to be bringing back all my members rather than just the name I search for.

        2. The blog search seems to be working to an extent in that it returns results that contain the search term in the post, but it does not seem to be returning results that have a matching tag or category. For example if I have a post in category "Fruit" with a tag of "Apples" – I would expect it to appear under blog search results if I typed in the term Fruit, or if I typed in Apples.

        thanks for your help so far

        cheers

        Dave

        • Hi Brajesh

          Have you had a chance to look at either of these issues?

          thanks

          Dave

  • Well, not really working at all. No matter what I search for (eg. Jannis – Member Name), your plugin lists all members, all groups and all blog-posts.

  • Pingback:Användbarhet och sociala intranät | Webbstrateg.nu

  • WP 3.5.1
    BP 1.6.4

    Great plugin, it works really well. It have an issue on login or logout and I can't find why is it happening. All website features, buttons and pages are working with any problem even if you use Unified Search, but, when I logout, or login, website breaks and it shows me a blank page. Can you help me? Cheers, I love your work

    • Hi Cell,
      Can you please point to the site. seems a little bit strange to me.

      • Hi Brajesh thanks for your reply. Unfortunately can't link you to my website because it isn't online yet, but when I tried to do login and logout on a completely new BP and the issue has simply disappeared. I think it was a plugin incompatibility, or something related with sidebar. I've moved all content to new file and everything works fine. Sorry by the incovenience and thanks for your time Brajesh, you are a good guy. Cheers.

        • Thank you for the updated info. I am glad that the issue is gone. There is no inconvenience, our goal is to help here.

          Cheers 🙂

  • Great plugin Brajesh, I've been using it for a while.

    Is it possible to make it work with the standard WordPress search widget, or to create a widget for it?

    I think to do the former I need to create some hooks to change the existing search widget, but I'm not sure how.

    I think it would be a very useful addition to the plugin, though.

  • Hello Brajesh Singh,
    I installed the Plugin, uploading the zip file of the BuddyPress Global Unified search 1.0.2 in the WordPress add Plugin installation dialog.
    Then I copied the code out of the functions.php (without the leading <?php ) into my themes functions.php and placed the two search files in the theme.. and as it did not work also in the bp-default theme.
    The search function is still not working.
    What am I doing wrong?
    I am useing WP 3.5.1 BP 1.7 BuddyPress Global Unified search 1.0.2
    Thanks a lot for your work.

  • FWIW i just treid upgrading to BP 1.7.1 and received the following error:

    PHP message: PHP Fatal error: Call to undefined function bp_is_current_component()

    • It looks like if you comment out all the unified search code and run the update things work out, then you can just uncomment the code and the search is back to normal. I'm not sure why this would be the case but…

      Also it might be the fact that im only using this plugin to get buddypress to search forum topics but removing the plugin/bp-global-unified-search folder seems to have no adverse effects :/

      • Hi Brad,
        you are right about that. In my next update I will put a check for whether buddypress is active or not.

  • hi Brajesh, after BP update to 1.8 it looks like that on single pages I get the error "Warning: strstr() [function.strstr]: Empty delimiter in …wp-content/plugins/buddypress/bp-core/bp-core-template.php on line 864" because of the Unified Search.

    Does anyone get the same error?

    thanks!

    • Hi James,
      I am sorry for the delayed reply. I haven't tested this plugin with Bp 1.8 yet. will be doing tomorrow and posting back.

      Thanks
      Brajesh

  • It looks like this plugin is no longer working with BuddyPress 1.8. They seem to have changed the way search works.

    • Hi Jared,
      Thank you for the comment. I haven't tested this plugin with BuddyPress 1.8 yet personally. I will be testing tomorrow and will get back to you.

      Thanks
      Brajesh

  • I confirm it doesn't work. When activated it gives warnings:

    Warning: Creating default object from empty value in /wp-content/plugins/bp-global-unified-search/bp-global-unified-search.php on line 50

    Warning: Creating default object from empty value in /wp-content/plugins/bp-global-unified-search/bp-global-unified-search.php on line 51

    Warning: Creating default object from empty value in /wp-content/plugins/bp-global-unified-search/bp-global-unified-search.php on line 52

    Warning: Creating default object from empty value in /wp-content/plugins/bp-global-unified-search/bp-global-unified-search.php on line 53

    Warning: Creating default object from empty value in /wp-content/plugins/bp-global-unified-search/bp-global-unified-search.php on line 54

    Warning: strstr(): Empty delimiter in /wp-content/plugins/buddypress/bp-core/bp-core-template.php on line 864

  • Hello Brajesh, can you please update this tutorial and plugin for the latest WordPress & BuddyPress version? This is something I have been trying to do for ages but can't.

    • Than you for the comment and bringing it back. I will have an update by the weekend 🙂

      • Thanks a lot Brajesh, I will be on the lookout for it 🙂

      • I would love an update for this too!! Running buddypress 1.8 – this is EXACTLY what I need!!

        Thank you for all your hard work, Brajesh!

      • Will have an update By Wednesday Day. I am working on it 🙂

        • Any updates yet?

        • Hello Brajesh,

          With all your running around and developing, have you been able to work on this? 🙂

  • Hi Brajesh!

    I'm looking to install this plugin for the first time, but unfortunately I'm running BuddyPress 1.8. I noticed in the comments that the plugin needs some updating before it's compatible with 1.8. Have you had any time to look into this?

    Also, this is a great plugin and you should provide a premium version to get paid for all your hard work.

  • Hey Brajesh! Any word on the 1.8 update??

    Thanks so much!

    Will

  • Hi Brajesh, any word on 1.8+ compatibility? I appreciate you're doing this off your own back, is there a way we can help you? Getting things moving on Github perhaps?

    • Hi Matt,
      Thank you for the comment.
      I haven't updated it for BuddyPress 1.8+ due to lack of time. BuddyPress 2.0 has released and I am working on updates for all of our code. Expect an update in next 3-4 days. The plugin( and all of my free plugins not only this) is already on github.
      https://github.com/sbrajesh/bp-global-unified-search

      Thank you
      Brajesh

  • Hi Brajesh, I'm using buddypress 2.2.3 and was wondering will this work with my website or not?

  • Hi guys,

    Can I use this plugin to create search form with only select profile fields? E.g., search form will consist of Male Female radio button and drop down menu for City or Race? And, most importantly, will it be compatible with your Conditional Profile Fields plugin? Thank you!

    • Sorry, forgot to mention: if that is indeed doable, I will purchase the one-year support. I think that's only fair 🙂

      • Hi Konberg,
        Thank you for the comment and asking. I believe this plugin is not best suitable for your purpose. What you are looking for is Andrea's plugin
        https://wordpress.org/plugins/bp-profile-search/

        I am working on a compatibility with member type field for the profile search plugin ( Thanks to Andrea for providing the hooks) and It will be available in 1-2 days in the update.

        • Awesome! Thank you so much, guys! Yes, I am currently using Andrea's plugin, and it is great.