Skip to:
Content
Pages
Categories
Search
Top
Bottom

groups_get_groupmeta in functions.php


  • tim.samuelsson
    Participant

    @timsamuelsson

    Hello,

    Im trying to run the function groups_get_groupmeta() in the themes functions.php file but it wont return any results.

    When i Use it inside the settings_screen method of a class thats extending BP_Group_Extension it works fine with the same arguments.

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

  • Henry Wright
    Moderator

    @henrywright

    That’s strange. I’m assuming you’re passing it an actual group ID (integer)? That’s required. Can you var_dump what it’s returning?


    tim.samuelsson
    Participant

    @timsamuelsson

    The result is an empty array. Im setting $single = false.

    If i run it like this in functions.php:

    add_action('bp_groups_setup_globals', function() {
        var_dump(groups_get_groupmeta(2, 'google_group_name', false));
    });

    It returns the following (Which is correct):
    array (size=4)
    0 => string ‘vmu’ (length=3)
    1 => string ‘alla’ (length=4)
    2 => string ‘digital’ (length=7)
    3 => string ‘linuxbackup’ (length=11)


    shanebp
    Moderator

    @shanebp

    It’s probably a timing issue. You’re calling it too early.
    Try this hook:

    function tim_check() {
        var_dump(groups_get_groupmeta(2, 'google_group_name', false));
    }
    add_action( 'bp_ready', 'tim_check', 11);

    Henry Wright
    Moderator

    @henrywright

    Good shout @shanebp.

    Also, looking at the groups_get_groupmeta() function definition, I’m wondering why we need to filter the query string with bp_filter_metaid_column_name?

    Anyway, alternatively, this may work but I haven’t tested:

    $retval = get_metadata( 'group', $group_id, $meta_key, $single );
    var_dump( $retval );

    Edit: Looks as though there is a reason BuddyPress uses bp_filter_metaid_column_name to filter the query. So my above might not work when it comes to BP.


    shanebp
    Moderator

    @shanebp

    afaik, bp_filter_metaid_column_name is used so that quotes in column names are not a problem.
    It is called in several functions.
    bp-core\bp-core-filters.php > function bp_filter_metaid_column_name


    Henry Wright
    Moderator

    @henrywright

    Just looked it up

     * Filter SQL query strings to swap out the 'meta_id' column.
     *
     * WordPress uses the meta_id column for commentmeta and postmeta, and so
     * hardcodes the column name into its *_metadata() functions. BuddyPress, on
     * the other hand, uses 'id' for the primary column. To make WP's functions
     * usable for BuddyPress, we use this just-in-time filter on 'query' to swap
     * 'meta_id' with 'id.

    Seems as though it’s used to make WP *_metadata() functions compatible with BP.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘groups_get_groupmeta in functions.php’ is closed to new replies.
Skip to toolbar