wp_get_current_user always returns 0

wp_get_current_user() is actually just a wrapper for $current_user and get_currentuserinfo(), so you can use both. It’s important, though, to only call it on or after the init hook. Calling it before will only return 0, as you’ve experienced.

Problem storing arrays with update_user_meta

Haven’t used the function for quite a time, but i guess your problem is that you are pushing an array into an array. So check if intval($_GET[‘auction’]) is an array: echo ‘<pre>’; print_r(intval($_GET[‘auction’])); echo ‘</pre>’; Edit #1: You maybe need to get the value from that array and then array_push it. So maybe something like … Read more

Capabilities Vs User Meta

There is no one answer, because both have pros and cons depending on what you want to store and why. A (probably non-exhaustive) list of differences to consider for a choice: Capabilities are designed to check if a user can do something or not. user_can and current_user_can are there to help you to check user … Read more

Return all users with a specific meta key

You can use the just the meta_key argument, the result will be similar to using the EXISTS sql statement. <?php $users = get_users(array( ‘meta_key’ => ‘your_meta_key’, )); Alternatively, you can use an empty string for meta_value (the default) and > for meta_compare. The result is the same (probably because meta_value gets ignored if its empty!). … Read more

get_user_meta() to Return User Meta Only for Current Blog in Multi Site

WordPress distinguishes usermeta keys between sites by using the database prefix for each site. For example, instead of using the favorite_posts key, you’d use the meta key wp_23_favorite_posts. To get the prefix, you can use $wpdb->get_blog_prefix(). But wait, there’s actually a whole API dedicated to this. Rather than using *_user_meta(), use *_user_option(). These are internally … Read more

wp_update_user doesn’t update and update_user_meta does

wp_update_user & metadata wp_update_user updates records in the *_users table. It isn’t meant to update custom metadata in the *_usermeta table. Hence your “problem” is actually expected behavior. The $userdata argument passed to wp_update_user can contain the following fields: ID, user_pass, user_login, user_nicename, user_url, user_email, display_name, nickname, first_name, last_name, description, rich_editing, user_registered, role, show_admin_bar_front Further … Read more

Query users by custom taxonomy and user role

Apparently there is no core implementation of ‘tax_query’ in WP_User_Query yet. Check the ticket here for more info –> https://core.trac.wordpress.org/ticket/31383 Nevertheless there is an alternative way using get_objects_in_term $taxonomy = ‘shop-category’; $users = get_objects_in_term( $term_id, $taxonomy ); if(!empty($users)){ // WP_User_Query arguments $args = array ( ‘role’ => ‘shop_manager’, ‘order’ => ‘DESC’, ‘orderby’ => ‘user_registered’, ‘include’ … Read more