Articles of get users

Cannot retrieve active members only

Below is a page template where I’m trying to retrieve active members metadata (of Restrict Content Pro). Displaying users’ meta is working just fine; but I can’t get ONLY active members to display, rather than everyone. I wondered if perhaps there a simple error in the syntax below that might correct this. I need to […]

List of users with email and role

I’m looking to create a list of all the users on my wordpress site with their email and role. $blogusers = get_users(); // Array of WP_User objects. foreach ( $blogusers as $user ) { echo ‘<span>’ . esc_html( $user->user_email ) . ‘</span>’; echo ‘<span>’ . esc_html( $user->roles ) . ‘</span>’; } This function is sort […]

How do I change the home page to the registered user's profile page

I have a custom profile page for my users. I need to have wordpress redirect the homepage to the user’s profile page if they are logged in. If they are not logged in or registered, wordpress would show the normal home page. My homepage url string would look like this for logged in users: […]

'pre_user_query' interfering with user export

I needed to add sortable columns to clients wordpress for custom meta data I created so I used a pre_user_query hook add_action(‘pre_user_query’, ‘user_column_orderby’); function user_column_orderby($user_search) { global $wpdb, $current_screen; if ( ‘users’ != $current_screen->id ) return; $vars = $user_search->query_vars; if(‘Kön’ == $vars[‘orderby’]) { $user_search->query_from .= ” INNER JOIN {$wpdb->usermeta} m1 ON {$wpdb->users}.ID=m1.user_id AND (m1.meta_key=’gender’)”; $user_search->query_orderby […]

Suggest Users basing on User taxonomy

My question is for getting informations or directions about how to move for a task I have to do. This is just a request for advices due to the fact I’m not an expert in wordpress development. My task would be to create a module (widget or just a query) which suggests registered users based […]

Let logged-in users use radio buttons (yes and no) to exclude their author profile from the user listing

I would appreciate if someone could point me in the right direction because I am stuck when it comes to solving the following issue. So I have a directory listing of WordPress users ( I use get_users query to output users. I would like to create a function, which will give logged-in users ability to […]

Display current user's custom post meta in sidebar

I’m trying to find a way to display the current user’s custom post (each user has only 1 post) content/meta in the sidebar, so the current user can see their custom post’s meta. This is what I have so far but I think need to add wp_get_current_user()->ID somewhere… What I have currently… <?php $authorid = […]

How get meta from all users?

I want to get all users with their respective data. I already get all the users: $users = array(); $users_query = new WP_User_Query( array( ‘role’ => ‘subscriber’, ‘orderby’ => ‘user_registered’, ‘number’ => 8, ‘order’ => ‘DESC’, ‘fields’ => array(‘ID’, ‘display_name’) ) ); $results = $users_query->get_results(); But I only get the data from user table: object(stdClass)#3162 […]

WooCommerce Admin order – Only run action if user is loaded

I am using this plugin to switch users. I have found a snippet that allows you to switch user on the WooCommerce admin order page which is very helpful. add_action( ‘woocommerce_admin_order_data_after_order_details’, ‘ccef_order_switch_to’, 99 ); /** * Add a switch to user link on the order details. * * @param object $order The WC Order that […]

Get User ID from within a plugin

I want to get the current user id from inside my plugin and use it as a variable. My code is $current_user = wp_get_current_user(); $user_id = $current_user->ID; $loc_statuss = $wpdb->get_row( “SELECT status FROM profile_location INNER JOIN relation_user ON profile_location.loc_id=relation_user.loc_id WHERE relation_user.user_id=$user_id” ); $loc_status = $loc_statuss->status; I have found a couple of questions the same but […]