Skip to:
Content
Pages
Categories
Search
Top
Bottom

Searching for custom group fields?


  • timrourke
    Participant

    @timrourke

    Hello,

    I’m trying to understand how to include custom group fields in my BuddyPress group search results. I’ve added custom group fields to my groups using this tutorial: https://codex.buddypress.org/plugindev/how-to-edit-group-meta-tutorial/

    The fields work fine, but aren’t part of the BP Groups search query. What’s the best way to add them? Is this something I need to create a custom WP_Query for, or is there a filter I should be making? Any suggestions would be awesome.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

  • timrourke
    Participant

    @timrourke

    By the way, I just saw this on line 40 of /buddypress/bp-templates/bp-legacy/buddypress/groups/create.php:

    do_action( 'groups_custom_group_fields_editable' ); // @Deprecated

    Does this mean that the function groups_custom_group_fields_editable is a deprecated function? The ‘@Deprecated’ note is in a template file.

    Also, if it is deprecated, what should I be doing instead to add custom group fields?

    Thanks!


    shanebp
    Moderator

    @shanebp


    timrourke
    Participant

    @timrourke

    Shane,

    As always, you’re super helpful! I’m almost there now.

    http://pastebin.com/1xXw9rd9

    One thing I still can’t figure out, however, is how to properly get my search string data into the meta query argument. This is what I have currently:

     $gbgd_bpgf_querystring['meta_query'] = array(
        	'relation' => 'OR',
            array(
                'key'     => 'group-custom-field-zip',
                'value'   => $gbgd_bpgf_querystring["search_terms"],
                'type'    => 'numeric',
                'compare' => 'LIKE'
            )
        );

    This doesn’t return any results. However, if I type the value for the above key directly into the array, for example I type:

    $gbgd_bpgf_querystring['meta_query'] = array(
        	'relation' => 'OR',
            array(
                'key'     => 'group-custom-field-zip',
                'value'   => 12345,
                'type'    => 'numeric',
                'compare' => 'LIKE'
            )
     );

    I’m able to get results. Any idea what I’m doing wrong here? I’ve var_dumped my values out to make sure they’re equivalent, tried typecasting the value to an int, etc.

    BTW, in case it wasn’t obvious, I’m not using an option/select menu, but trying to grab search queries entered on the groups page.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Searching for custom group fields?’ is closed to new replies.
Skip to toolbar