Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Add activity meta

  • Profile photo of mpa4hu
    mpa4hu
    Participant

    @mpa4hu

    Hello

    I found function which acts as bp_activity_update_meta but has not found any function which will do exactly it.

    I mean this function will search for meta, if it exist it will replace it, else create new one.

    I want to add multiple metas for the same activity with same name name, so update will not do.

    Of course I can write my own SQL, but since I didn’t found such function maybe it does not even exist – so here comes my doubts: maybe its not right to do this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    function add_meta_to_activity( $content, $user_id, $activity_id ) {
    
        $value = array(
         'key1' => 'val1',
         'key2 => 'val2'
        );
    
        bp_activity_update_meta( $activity_id, 'key', $value );
    
    }
    add_action( ‘bp_activity_posted_update’, ‘add_meta_to_activity’, 10, 3 );
    Profile photo of mpa4hu
    mpa4hu
    Participant

    @mpa4hu

    This does not answer my question and this is just a way to save array to meta.

    The thing I want is to insert multiple metas with the same key
    And question is if its breaks something, if not I can write function myself.

    Profile photo of mpa4hu
    mpa4hu
    Participant

    @mpa4hu

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    BP 2.0 adds bp_activity_add_meta()

    https://buddypress.trac.wordpress.org/browser/trunk/bp-activity/bp-activity-functions.php#L658

    But I’m not sure you can have same key. There is $unique which seems to imply you may have multiple values.

    // cc @boonebgorges

    Profile photo of mpa4hu
    mpa4hu
    Participant

    @mpa4hu

    Interesting

    The idea came when I was searching for solution and found this

    http://imathi.eu/2013/09/18/find_in_set-meta_query/

    I was implementing find_in_set meta query and read the comment below by Willy. Since I don’t want new table for something simple, this sound like a good idea

    Wordpress allows same key for multiple metas.
    Now when I look at that function I think this should allow too, but I want some confirmation before I continue.

    	 * @param bool $unique. Optional. Whether to enforce a single metadata value 
     	 *        for the given key. If true, and the object already has a value for 
     	 *        the key, no change will be made. Default: false. 
    Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    @modemlooper is correct: bp_activity_add_meta() will let you do what you’re looking to do. It’ll be available in BP 2.0.

    Profile photo of mpa4hu
    mpa4hu
    Participant

    @mpa4hu

    Thanks for great support.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Add activity meta’ is closed to new replies.