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> <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> <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: </b>' . $location . '</span>';
echo '<br><span><b>Rating:</b> ' . $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() || ''
},
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.
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