Shortcode for Listing Users from Meta Value?

It’s a small coding mistake.. It’s not displaying anything because when there are results, the end output is always a </ul> because you’re always overwriting the $results and not appending output to the variable: $results=”<ul>”; foreach ($users as $user){ $results=”<li>” . $user->display_name . ‘</li>’; } $results=”</ul>”; So the proper code is: $results=”<ul>”; foreach ($users as … Read more

Add custom user meta data

Adding custom field to all existing users. You will have to get the list of users and then, in a loop, set a custom field for each of them. $users = get_users( [ ‘fields’ => ‘id’, ‘meta_key’ => ‘YOUR_META_KEY’, ‘meta_compare’ => ‘NOT EXISTS’ ] ); if ( is_array($users) && count($users) ) { $meta_value = false; … Read more

Update a user profile via frontend

I’ve written this in a hurry and it’s untested and probably sloppy code, but it gives you an idea of how to accomplish this with AJAX. <form id=”update_user”> <div class=”form-group”> <label for=”firstname”>Name</label> <input type=”text” name=”firstname” id=”firstname” value=”<?= esc_attr(wp_get_current_user()->user_firstname) ?>” placeholder=”Vorname”> </div> <div class=”form-group”> <label for=”name”>Name</label> <input type=”text” name=”name” id=”name” value=”<?= esc_attr(wp_get_current_user()->user_lastname) ?>” placeholder=”Name”> </div> <div … Read more

How to get user ID’s from multiple usernames?

Your call to get_user_by() has a small hiccup in it. It needs to be login rather than user_login // Search these Usernames $usernames = array(‘user1’, ‘user2’); // Fetch the User IDs $prof_ids = array(); foreach ($usernames as $prof_id) { $user = get_user_by(‘login’, $prof_id); $prof_ids[] = $user->ID; } // WP_User_Query arguments $args = array( ‘include’ => … Read more

Get user by meta key – WP multi site

This is the problem: $user = reset( get_users( reset expects a reference to an array, and there’s no mechanism for error checking. So even if it finds the user, you’re misusing the return value. It might be possible to adjust this to use references properly, but references in PHP are something best avoided, and there … Read more

Change/Set Page Title and Meta Tags from Page Called within a Plugin

Attach to wp_head action hoook function that will display meta tag. Inside that function you can: add your own filter that will allow you to change the value, or change tag value depending of your query vars (sign1, sign2, …) or conditional tags. add_action( ‘wp_head’, ‘se344297_description_metatag_display’, 0 ); function se344297_description_metatag_display() { $site_descr = apply_filters( ‘description_tag_filter’, … Read more

User Meta Value not echoing despite Var_Dump Showing correct string

The $havemeta variable isn’t defined inside your shopping_location_text() function, so it isn’t available for use there. For a quick fix (or for testing/toying) you can move your code inside the function, like this: add_action( ‘woocommerce_before_main_content’, ‘shopping_location_text’, 10 ); function shopping_location_text() { global $current_user; get_currentuserinfo(); // wordpress global variable to fetch logged in user info $userID … Read more

Custom Field Repeating When Using foreach

if you want to use multiple users, if you will add usernames comma separated in custom field. try below code. function user_avatar() { $user = “”; $names = get_post_meta( get_the_ID(), ‘user_name’, true ); $user_names = array_map(‘trim’, explode(‘,’, $names)); if(!empty($user_names)) { foreach ($user_names as $key => $user_name) { $user = get_user_by( ‘login’, $user_name ); if($user) { … Read more

If Array Values Match Another Array’s Values, Then

Here’s one way to solve this: sort both arrays loop through them and compare them item by item (they should be equal, because arrays are sorted) . sort( $evaltypesReq ); sort( $evaltypesSch ); $containsAllValues = true; foreach ( $evaltypesReq as $k => $v ) { if ( $evaltypesSch[$k] !== $v ) $containsAllValues = false; }