Checking if meta_value exists for any user

I'm using gravity forms for a sign-up form and I set up a hidden field that is automatically filled with a random string generated and passed to the form by add_filter("gform_field_value_random_number", "generate_random_number"); function generate_random_number($value){ $value = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ,5)), 0, 7); } This is to use as a unique coupon code/user.This field also appears in their user profile. Up to here all is well. Where I'm having trouble is checking the database that no user already has that coupon code. At …
Category: Web

How to add custom detail page for a Subscriber at Admin Panel

I have created a custom page which shows the list of Users(Role = 'Subscriber'). I named this page "Reporting" & It is based on wp_list_table. Now I want to show the user details (having custom layout & user meta). I am not sure How to create a link of user detail page or create a detail page. Here is the code which shows User lists Data. class-cisco-connex-core-wp-reporting-table.php class WP_Reporting_Table { /** * Constructor */ public function __construct() { // Hook …
Category: Web

Create membership number for existing/new users

I have a membership site with 4000+ users currently on it. I am needing to give both new/existing users an automatic ID number. its very similar to this: Create Unique ID for user However, this only works for new users, I need it to work for the current users too. So for instance, user id 3421 would get membership number 3421. This is what I have so far: (pretty much all from above link) function fb_add_custom_user_profile_fields( $user ) { ?> …
Category: Web

Sort users by meta key value even if meta key not present for all users

Only some users have a specifice meta_key some_metakey associated with their ID. The following args successfully orders users with a specified role by some_metakey but only those with that meta_key. Can anyone point the direction to change the args to include ALL users with a specified role even if they do not have the some_metakey meta_key? $args = array( 'role__in' => [ 'role1', 'role2', 'role3', 'role4' ], 'order' => 'DEC', 'meta_key' => 'some_metakey', 'orderby' => 'meta_value' ); $users = get_users( …
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

User list order by user meta

i have created user vote that can vote users or author of posts. so for example have 4 users which looks: user --- ID=1 --- META KEY='_thumbs_rating_up' --- META VALUE='13' user --- ID=2 --- META KEY='_thumbs_rating_up' --- META VALUE='17' user --- ID=3 --- META KEY='_thumbs_rating_up' --- META VALUE='8' user --- ID=4 --- META KEY='_thumbs_rating_up' --- META VALUE='241' So i must order these users by user meta key and meta value from heighest to lowwer. So i have these code now …
Category: Web

Linking form to user meta fields

I currently have my login page set up to allow sign up through google. Immediately after a successful sign up I'm looking to set up a redirect to a form where the user can enter additional details and these are saved within predefined user meta fields. I know how to set up the fields using ACF or Pods. Are there free plugins available which can link a form to the meta fields? I'm fairly new to developing hooks but if …
Category: Web

Auto populate a user custom field from another user custom field

I have a WP theme with its own custom fields including one for Phone Number. I also installed the Digits Plugin which allows users to sign up/login with their phone number and OTP, which has its own phone number custom field. What I want to do is to use the phone number they use to sign up/login to also be the phone number used within the theme and also within Woocommerce if possible. Any help would be appreciated
Category: Web

Display custom image field in user profile

I am trying to display user info from acf so far the normal text, radio and select and date fields display if I use the following: <?php $current_user = wp_get_current_user(); echo $current_user->user_gender; ?> I have created 2 image custom fields one of each I would like to use as an avatar. Ho do I get the images to display if the custom field name is user_banner and user_avatar. the fields are custom fields from acf are user_banner and user_avatar. Here's …
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

Using wp_login vs login_redirect to redirect based on user-meta

I wrote a function to redirect first-time users using login_redirect, and it was working great. Then I changed the hook to wp_login (to get it to play well with a social login plugin), and now the function is redirecting all users who sign in via the wp_login_form. PS: the redirect works fine when logging in via my social login plugin. Is there a difference between wp_login and login_redirect, or is something wrong with the conditional php? Here's the code: //Hook …
Category: Web

Add WordPress user custom meta to chartjs vertically stacked chart in Divi theme

I have created a user dashboard using the Divi theme where I need to add a chart like the attached screenshot. The data are specific for every different user. I have tried many premium plugins but none of them fits my requirement. This is how I added the user meta - <?php function hfa_custom_user_fields( $user ) { $services_subscribed_options = array( 'Airbnb' => 'Airbnb', 'Vrbo' => 'Vrbo', 'Trucking' => 'Trucking' ); $services_subscribed = get_user_meta($user->ID, 'services_subscribed', true); $services_subscribed = (array)unserialize($services_subscribed); $total_invest = …
Category: Web

check for duplicate user meta data before updating

I have added the ability for a social security number to be added for users. This field can be edited on the individual users screen but the data is saved to the usermeta table. When editing a new user, I want to check if that number is being used somewhere else for another user as duplicates should not be allowed. My initial code is: function save_cust_user_profile_fields( $user_id ) { if ( isset($_POST['social_number']) ) { update_user_meta( $user_id, 'social_number', intval($_POST['social_number'])); } } …
Category: Web

I want to update my user meta table

I have a form with the fields name, address, class, and age. When I enter a new registry, the name field gets updated in the table wp_users. Once the ID is saved, I am trying to update the user meta fields such as address, which is not happening. Below is my PHP code. Please Help me: <?php $userdata = array( 'user_login' => $_POST['usname'], 'user_pass' => $_POST['passw'] // When creating an user, `user_pass` is expected. ); $user_id = wp_insert_user( $userdata ) …
Category: Web

Compare User meta_value with Product meta_value

In Wordpress I've added a new field called "user_branche" on the user edit profile page within the admin. On the Woocommerce product page in the admin I added a meta field called "product_branche". Now I need a database query to compare these. I only want to show the products with the same value for "user_branche" as "product_branche". I've spent some hours researching but I can't figure it out. I tried using this: SELECT t1.* from wp_postmeta t1 left outer join …
Category: Web

author.php not showing content if Author has no Posts

I am making a custom Genesis theme, and have a custom author.php file that pulls in various custom fields (Using Advanced Custom Fields), and author meta information to the page from the author profile page... It also displays their latest posts. This works perfectly, IF the author has posts assigned to them. If they don't, the page doesn't output any of the content that is normally pulled from the authors profile... I've searched StackExchange, and whilst this has been mentioned …
Category: Web

How to change the value of a variable using input field?

I have created a wordpress website. I want to extract each user's data using php through his/her id. I have created this code; <?php $userid = /* help me get the below input field's value */ $user_info = get_userdata($userId); echo 'Username: ' . $user_info->user_login . "\n"; echo 'User roles: ' . implode(', ', $user_info->roles) . "\n"; echo 'User ID: ' . $user_info->ID . "\n"; ?> <input name="getUser" id="getUser" value=''/> The user will write the id of the user he wants …
Category: Web

Multiple meta values for one meta key

I have one meta key "game" containing this meta value "game 1, game 2". I would like to display this meta value on my site like this: <a href="http://www.url.com/game-1">game 1</a> <a href="http://www.url.com/game-2">game 2</a> Thanks for your help.
Category: Web

How to store checkbox data for individual users?

I am working on a video-course website and I would like to add a checkbox next to each video so that when a student finishes watching the video, they can mark it complete and when they return they will know where to start again. Each student goes through 200+ videos across 12 different pages, so I would just need to duplicate this functionality for each video and I guess store the "check/uncheck" status individually for each. My guess is: HTML/CSS …
Category: Web

About

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