Users Select inside custom metabox

I think the problem is you are passing the WP_User_Query object, not the results of the query. Try to change: $fields = array( array( ‘id’ => $prefix . ‘user_sub’, ‘name’ => ‘Subscriber User’, ‘type’ => ‘select’, ‘use_ajax’ => false, ‘options’ => $user_query, // this is where you populate the select in metabox ), ); To: … Read more

Last Login in number of days format

Okay, there are a couple of things to do: Get last_active for the user Calculate the days since last_active Set last_active_days_ago for the user So you can go like this: function daysAgo( $time ) { $time = time() – $time; $daysAgo = $time / 86400; // calculate days return $daysAgo; } function set_user_last_active_days_ago( $user_id ) … Read more

WP_user_query throws a 404 error

pre_user_query is called after the query variable object is created, but before the actual query is run. Your code is creating a new query within the action when you should actually modify the existing query’s arguments using the $query->set() method. For example: function my_pre_user_search($user_query) { $meta_query = array(array( ‘key’ => ‘member_id’, ‘value’ => ‘2349’ )); … Read more

How to use an associative array in post__in with WP_Query?

Take a look at PHP’s array_values function. Alternatively, you could typecast. Note that if the array is in serialized form as you have put it above, you will have to unserialize it first, in either case. $numerical_array = array_values( unserialize( ‘a:1:{s:8:”post-134″;s:3:”134″;s:8:”post-136″;s:3:”136″;}’ ) ); or $numerical_array = (array) unserialize( ‘a:1:{s:8:”post-134″;s:3:”134″;s:8:”post-136″;s:3:”136″;}’ );

How to save multiple options from a dropdown in user profile

You will need an opening select tag that tells PHP it is an array. Something along the lines of the following should get you on your way… <?php // Display Fields add_action( ‘show_user_profile’, ‘add_multiple_choice_dropdown ‘ ); add_action( ‘edit_user_profile’, ‘add_multiple_choice_dropdown ‘ ); function add_multiple_choice_dropdown ( $user ) { $current_selections = get_user_meta( $user->ID, ‘multi_dropdown’, true ); ?> … Read more

Get an array of meta_values for a user meta_key

You just need to add a DISTINCT to your SQL query, something like: $cities = $wpdb->get_col(“SELECT DISTINCT(meta_value) FROM $wpdb->usermeta WHERE meta_key = ‘my_cities_meta_key'” ); Alternatively, if you want to do it with php for some reason (if you want to know that a city is listed twice before displaying only unique entries) $cities = $wpdb->get_col(“SELECT … Read more

How to use Buddypress xProfile field as WordPress Bio

To just answer this question.. Hope it’s okay to pull this back up ^^ <div class=”profile-bio”> <!– Profile user info bio text –> <?php if ( $string = xprofile_get_field_data( ‘About’, get_the_author_meta(‘ID’) ) ) { echo ‘<div class=”author-about”>’; echo $string; echo ‘</div>’; } ?><!– EOF Profile user info bio text –> </div> I’m also using this, … Read more