Skip to:
Content
Pages
Categories
Search
Top
Bottom

Use bp_has_groups() without search parameter

  • @offereins

    Participant

    Using WP 3.8.1 + BP 1.9.1, when developing with BuddyPress I’m faced with the following issue.

    On an WP admin page that serves a WP_List_Table with a common search box (like posts.php or users.php) any default bp_has_groups() query call returns just that what you’d expect: all available groups. But when the search box is used to filter the elements within the list table and an 's' query parameter appears in $_GET and $_REQUEST, the groups query reads the search terms for the groups query, thus returning only groups that match the 's' query parameter. This happens on line 340 of bp-groups/bp-groups-template.php. Though understandable, this is not the desired result, since the groups query is absolutely separate from anything associated with the list table query elements.

    The only filter to modify the groups query from bp_has_query() untill the actual SQL execution is bp_groups_get_paged_groups_sql in BP_Groups_Group::get(), but it cannot receive any custom arguments from bp_has_query if I would want to bypass the search sql statement like that.

    One solution that works is to manually unset and reset the 's' query parameter before and after each bp_has_groups() call, but that’s not something I really like doing. Another similar way is to set a global flag for each time to ignore the search terms.

    Is this intended behavior?

Viewing 2 replies - 1 through 2 (of 2 total)
  • @boonebgorges

    Keymaster

    @offereins – Thanks for the post.

    Grabbing $_GET['s'] is, of course, intended behavior. But not allowing overrides – that, I would interpret as a bug. You can see the behavior here: https://buddypress.trac.wordpress.org/browser/tags/1.9.2/bp-groups/bp-groups-template.php#L335

    The proper fix is for us to sniff out querystrings *before* parsing the arguments passed to the function. That way, you can pass a null ‘search_terms’ parameter to bp_has_groups() to bypass our default behavior. Would you mind opening an enhancement ticket for this at https://buddypress.trac.wordpress.org?

    For the time being, you can continue to do what you’re doing by manually setting/unsetting $_GET['s'], or you can filter the clause out of the SQL statement, both of which you’ve suggested above. The only other workaround that comes to mind is something like passing a space character ' ' as a search_terms param – though even that might miss groups with one-word names and descriptions.

    @offereins

    Participant

    Thanks for your feedback. Ticket created at https://buddypress.trac.wordpress.org/ticket/5456.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use bp_has_groups() without search parameter’ is closed to new replies.
Skip to toolbar