@puffyjoe
Active 9 years, 4 months ago
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
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() || '' },
I just wanted to say I got it working. this is my code to filter by the city I save in meta
public function activity_querystring_filter( $query_string = '', $object = '' ) { if( $object != 'activity' ) return $query_string; // You can easily manipulate the query string // by transforming it into an array and merging // arguments with these default ones $args = wp_parse_args( $query_string, array( 'action' => false, 'type' => false, 'user_id' => false, 'page' => 1 ) ); if( bp_is_user() ) $args['user_id'] = bp_displayed_user_id(); // try to use args $user_id = bp_loggedin_user_id(); $user_id = bp_loggedin_user_id(); $city = xprofile_get_field_data('9', $user_id); // $city = xprofile_get_field_data('9', $args['user_id']); //not sure if this is set right but could work // An activity meta query <img src="https://codex.buddypress.org/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;"> $args['meta_query'] = array( array( /* this is the meta_key you want to filter on */ 'key' => 'city', /* You need to get all values that are >= to 1 */ 'value' => $city, 'type' => 'CHAR', 'compare' => '=' ), ); $query_string = empty( $args ) ? $query_string : $args; return apply_filters( 'bp_plugin_activity_querystring_filter', $query_string, $object ); }//end method activity_querystring_filter
OK great tutorial I will work through it.
Thanks so much!
Viewing 3 replies - 1 through 3 (of 3 total)