WordPress get last inserted user id

I want to disable user_login field into my CMS. They are register only their email adress. I think to create secret user login by programmatically. I think for accessibility and manageability also I want to use their ID'. For this I want to know last user's ID. I know the unprofessional way of doing this. A way as below, <?php $args = array( 'orderby' => 'registered', 'order' => 'DESC', 'number' => 1 ); $users = get_users($args); $last_user_registered_ID = $users[0]->ID; But …
Category: Web

User with same Mail but a different additional info(like domain)

I know this is not the way u should go, but my customers want it so im looking for ways. Requirement: WP with one DB (3 Domains sale the same stuff) 3 Domains which use this DB (can be more later), this should work with on fly rewriting over hooks user registered should be only able to login in the domain where he is registered, but should be able to register on the other 2 domains with same data. My …
Category: Web

WP_User_Query not returning users with meta - what am I missing?

I think I'm missing a step here, but for the life of me I can't see it. I'm trying to display a simple list of users who all have the same role and have the same meta data value for a certain key - namely, teachers associated with a school. Here is my code: <div class="teachers-list"> <h3>Your School's Teachers</h3> <ul> <?php $champion_user = wp_get_current_user(); $school = $champion_user->school; // echo $school just to test it's right.... ?> Your school: <?php echo …
Category: Web

Parent User and Child User - relate users

I need to create a system in which I have 2 types of users: Company User (C) and Employee User (E). I need C to be able to register as many E as necessary and for C users to be able to publish articles that will only be visible to E users, children of C users. I figured it would be possible to do this with meta fields so I created the ACF DAD and CHILD field with Jet Engine …
Category: Web

Display the list of user's comments + the post title + date

I am trying to display the current user's ALL comments in a specific page and I'm using this code (uses a shortcode): https://blog.ashfame.com/2011/01/show-recent-comments-particular-user-wordpress/ And have modified it: <?php /* Plugin Name: Show Recent Comments by a particular user Plugin URI: http://blog.ashfame.com/?p=876 Description: Provides a shortcode which you can use to show recent comments by a particular user Author: Ashfame Author URI: http://blog.ashfame.com/ License: GPL Usage: */ add_shortcode ( 'show_recent_comments', 'show_recent_comments_handler' ); function show_recent_comments_handler( $atts, $content = null ) { extract( …
Category: Web

how to get list of all users and their metadata

How do I get a list of all users with role = 'Customers' including all the metadata per user, means wp_users + wp_usermeta. Query blow does not generate the wanted results. $query = "SELECT * FROM wp_users INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id ORDER BY ID DESC'); "; $data = $wpdb->get_results($query,ARRAY_A); But that list is not correct. It shows each user x times depending on the number of rows in wp_usermeta. How can I filter it? That each user …
Category: Web

How to order users alphabetically by name? in plugin UPME

I have this code: <?php class UPME_List_Cards { public $upme_options; public function __construct() { global $upme; add_shortcode('upme_latest_members_list', array($this,'latest_members_list')); } public function latest_members_list($atts){ global $upme_template_loader,$upme_list_card_params; extract( shortcode_atts( array( 'limit' => 10 , 'user_role' => '', 'template' => 'members_icon_mini', ), $atts ) ); $admin_users = get_users('role=administrator&orderby=registered&order=DESC'); $admin_users_list = array(); foreach ($admin_users as $admin_user) { array_push($admin_users_list,$admin_user->ID); } $display = ''; $args = array( 'exclude'=> $admin_users_list, 'number' => $limit, 'orderby' => 'registered', 'order' => 'desc', 'meta_query' => array( 'relation' => 'AND', 0 => array( …
Category: Web

WP User Query with meta queries

I'm having some problems when comparing integer values '>=' or '<=' with meta_queries with the WP_USER_QUERY. Let say I've stored the following meta keys with the meta values below: meta_key meta_value type type1 status active location London min_price 10000 max_price 20000 The query works fine for the meta keys 'type', 'status' and 'location'. But I'm having problems with the 'min_price' and 'max_price'. Below you can find the code I used to retrieve a list of users with the above meta …
Category: Web

WP_User_Query is Not Displaying Results

I'm trying to create a table with a list of users and it only seems to work when I have it set up like this: $user_report_query = new WP_User_Query( array( 'role' => 'Administrator' ) ); The array I'm trying to use is: $args = array ( 'role' => 'Participant', 'order' => 'ASC', ); Participant is a custom role which has already been set up. I can select the role when creating users from the role dropdown menu. But any time …
Category: Web

Query Users by post count, last 30 days and display each users post count according to post type

I'm almost done, the code below does everything but display post count for each user broken down into post types, and also I'm like to filter it last thirty days. I'm trying to get the post for each user fr the custom post type 'music'. <div id="top-artist-wrapper"> <?php foreach ( get_users('orderby=post_count&number=5') as $user ) : ?> <div class="top-artists"> <?php echo get_avatar($user->ID, '64'); ?> <div class="artist-name"> <?php echo $user->display_name; ?> (<?php echo count_user_posts( $user->ID, $post_type='music' ); ?> Posts) </div> </div> <?php …
Category: Web

Wp_user_query search by meta_key not returning any results

I have a search form, and im trying to have it be able to search both the basic user field (user_email, display_name, etc), plus 1 other custom user meta key called "clinic" heres the argument i have so far $args = array( 'orderby' => 'display_name', 'meta_key' => 'course', 'fields' => 'all', 'search' => $search, 'meta_query' => array( array( 'key' => 'clinic', 'value' => $search, 'compare' => 'LIKE' ) ) ); Also, not sure if i have this set up correctly, …
Category: Web

User query - getting values for custom meta keys/fields

I am beginner at customizing wordpress but have some experience in PHP coding. I'm struggling to figure out how to display all existing meta keys (custom fields defined by ACF) for all users that have role "author". Default fields display ok, but cannot get values of those meta keys / custom fields. The code below was created with wp generator and manually expanded. I tried here with only 2 default fields (user email and display name) and 2 meta custom …
Category: Web

Replace wp_query with wp_user_query

I'm turning out some subscriber archives and singles (profile pages) in my plugin where I'd also included a 'user-single' template, included via template_include. I'm experimenting however with trimming some of these templates out of my plugin in order to make it use theme templates. I've instead used locate_template( 'single.php' ) to choose the single template from the active theme. I'm not using the global wp_query to turn out my content in this case but the page shows a loop based …
Category: Web

How do I echo all users' display_name and their meta_value who have a certain meta_key?

I have a meta_key inside the table usermeta called 'sms_subscriber'. The meta_value for it is their phone number. I want to echo a list of all users who have that field; in other words, a list of each user's name, phone number, and the quantity. The page output might look something like this: SMS Subscribers (3) 1 ben blue +15553335555 2 bob bananas +445557778888 3 jerry johnson +13334445555 I have tried many different queries and have successfully echo an array …
Category: Web

Getting current user data with MySQL statement

There are many widgets in Elementor which allow using MySQL statements to populate some data field. What I am trying to do is populate a field with a specific user's order data. The problem I am running into is because these Elementor MySQL editors do not allow php I have to get the current user ID, etc... with only valid MySQL syntax. I am very new to developing in WordPress. Should I just grow a pair, move out of my …
Category: Web

Wrong result in fetching User meta of WordPress

I have custom post type Task where I assigned Users as Volunteers. Now I would like to fetch how many tasks assigned to a Volunteer. I am using below code. $users = new WP_User_Query(array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'last_name', 'value' => $_POST['search'], 'compare' => 'LIKE', ), ), )); $users_found = $users->get_results(); $names = array(); foreach ($users_found as $user) { $this_users_tasks = get_user_meta($user->ID,'task',false); $names[$user->ID] = $user->display_name.' ('.count($this_users_tasks).')'; } echo json_encode($names); die; But I am getting wrong …
Category: Web

How to query users to count all with a custom capability and limit it to a set of roles?

On a site with 12 custom user roles I need to count users with the 'supervisor' custom capability but limited to four specific roles. The following code counts all users with the 'supervisor' capability, but does not limit it to the specific roles: $args = array( 'role' => 'supervisor', //this is a custom capability 'role__in' => array( 'level1', 'level2','level3','level4' ) //these are custom roles ); $user_query = new WP_User_Query( $args ); $supervisors = count($user_query->results);
Category: Web

WP_User_Query ignoring 'meta_query' arguments

So, I'm trying to do a query on 'members' based on some inputs from a form using AJAX. The thing is that when searching for a 'role' I get the expected result. But once I try to look for other meta values, the return bring all members in the DB. I tried in a bunch of ways but I either get the result I just said, or I simply get no result at all (even with the role) Here is …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.