Using GROUP CONCAT in my-sql query with wp_usermeta table

How about a Pivot Query? This would return rows that have first_name,last_name,user_login. You could then add whatever condition you wanted using a WHERE clause. SELECT MAX(CASE WHEN wp_usermeta.meta_key = ‘first_name’ then wp_usermeta.meta_value ELSE NULL END) as first_name, MAX(CASE WHEN wp_usermeta.meta_key = ‘last_name’ then wp_usermeta.meta_value ELSE NULL END) as last_name, wp_users.user_login FROM wp_users LEFT JOIN wp_usermeta … Read more

Incrementally add or substract from usermeta field

The function below should do your job. function manage_credits( $operation = ‘add’, $amount = 0 ) { $user_id = get_current_user_id(); if ( $user_id ) { $user_credit = (int) get_user_meta( $user_id, ‘my_user_credit’, true ); if ( ‘add’ == $operation ) { $user_credit += $amount; //For adding credits } elseif ( ‘remove’ == $operation && ( $user_credit … Read more

Custom User Field in Dashboard Widget

There’s get_the_author_meta() for such a task. (get_* functions normally don’t echo/print the output – hence the name). // Both values are *optional* get_the_author_meta( $field, $user_id ); Normally it’s only meant to be used inside a loop to get the data of the posts author, therefore it internally uses global $authordata;. But, you can also throw … Read more

Sorting custom post type by usermeta

You have to add meta_key, orderby and order parameters to your query as described in the Codex: Order & Orderby Parameters: <?php $args = array( ‘post_type’ => ‘teacher’, ‘paged’ => $paged, ‘meta_key’ => ‘last_login’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’ ); $my_custom_query = new WP_Query($args); Also note I don’t use $wp_query variable to store the … Read more

How to save data of an input field to an array

Don’t use update_usermeta, it is deprecated, update_user_meta is the one to use. You get the previously saved value out with get_user_meta. <input type=”text” name=”group[]” id=’group[]’ class=”regular-text” value=”<?php echo esc_attr( get_user_meta( $user->ID, ‘group’, true ) ); ?>” />

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)