Skip to:
Content
Pages
Categories
Search
Top
Bottom

Activities Update – Adding new field, storing in meta, then display in activity


  • puffyjoe
    Participant

    @puffyjoe

    I would like to make a new activity type, which is an update but it has a new text field “hobby” so that when a user posts and update, they can type in what their hobby is.

    Then, when it saves, I’d like it to save in the meta table, since I already have some experience with that, unless there is a much better way.

    Finally, the activities list, when displayed, would show the hobby entered just below the regular “update” text that was entered.

    Suggestions how to go about it?

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

  • puffyjoe
    Participant

    @puffyjoe

    This is what I have so far. It doesn’t update the meta table correctly, only putting in the meta name not the values, which are blank

    
    function add_location()
    {
        echo '<div class="form" style="margin-top: 20px;">';    
        echo '<label style="font-weight: bold;font-size:2.1">loc? </label>&nbsp;&nbsp;<input value="" style="width: 200px; margin-right: 20px;" placeholder="" id="location" name="location" ><br><br>';
        echo '<label style="font-weight: bold;font-size:2.1">rating?</label>&nbsp;&nbsp;<select style="width: 140px;" id="rating" name="rating" >';
        echo '<option value="5">Amazing!</option><option value="4">Excellent</option><option value="3">Great</option><option value="2">So - So</option><option value="1">Sucks!</option>';
        echo '</select>';
        echo '</div>';
    }
    add_action( 'bp_activity_post_form_options', 'add_location', 10, 3);
    
    function add_rating_to_activity( $content, $user_id, $activity_id ) 
    {
    	bp_activity_update_meta( $activity_id, 'location', $_POST['location'] );
    	bp_activity_update_meta( $activity_id, 'rating', $_POST['rating'] );
    }
    add_action( 'bp_activity_posted_update', 'add_rating_to_activity', 10, 3 );
    
    function add_data_to_activity_item() 
    {
    
    	$location = bp_activity_get_meta( bp_get_activity_id(), 'location' );
    	$rating   = bp_activity_get_meta( bp_get_activity_id(), 'rating' );
    
    	echo '<br><br><span><b>I am at:&nbsp;</b>' . $location . '</span>';
    	echo '<br><span><b>Rating:</b>&nbsp;' . $rating . '</span><br>';
    
    //  ‘
    
    }
    add_action( 'bp_activity_entry_meta', 'add_data_to_activity_item',10,3 );
    

    I remember something about having to set the ids for the posted values in global.js? seems like I shouldnt have to put code into core files right? I tried modifying it for location to no avail…

    /* Default POST values */
    		var object = '';
    		var item_id = jq("#whats-new-post-in").val();
    		var content = jq("textarea#whats-new").val();
    		var ch_location = jq("input#location").val();
    
    		/* Set object for non-profile posts */
    		if ( item_id > 0 ) {
    			object = jq("#whats-new-post-object").val();
    		}
    
    		jq.post( ajaxurl, {
    			action: 'post_update',
    			'cookie': bp_get_cookies(),
    			'_wpnonce_post_update': jq("input#_wpnonce_post_update").val(),
    			'content': content,
    			'location':ch_location,
    			'object': object,
    			'item_id': item_id,
    			'_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
    		},
    

    Xtremefaith
    Participant

    @xtremefaith

    Any updates on this? So far this is the closes to an actual answer on this question. The documentation as expected is pretty quiet about the topic. It is very easy to add fields to the group activity form, but seems impossible to actually handler the the values posted. They don’t appear $instance variable of the bp_activity_after_save action. At the moment at a complete loss at what to do.


    r-a-y
    Keymaster

    @r-a-y

    Puffyjoe’s example should work in BuddyPress 2.4.0.

    BP 2.4.0 will pass all activity update form data, so you can save custom activity data a little bit easier.

    If you want to test, v2.4.0 is currently in release candidate status. Read the announcement post here:

    BuddyPress 2.4.0 Release Candidate 1

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Activities Update – Adding new field, storing in meta, then display in activity’ is closed to new replies.
Skip to toolbar