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; }

Show extra user profile meta for current user

You should use get_user_meta instead of get_the_author_meta(). because get_the_author_meta() has Valid values for the $field parameter include: get_the_author_meta you can take reference from below code. $school_id = get_user_meta( $current_user->ID, ‘school-id’,true); if ( !empty($school_id) ) { ?> <p class=”school-id”> <p> <?php echo $school_id; # what you want to do with school id ?> </p> </p> <?php … Read more

how to set default update_user_meta values wordpress

You can use the user_register action to run your user meta update when a user registers. /** * Sets the user meta key ‘_sb_pkg_type’ to ‘free’ when a user registers. * * @param int $user_id ID for the user who has registered. */ function wpse_update_user_meta_pkg_type( $user_id ) { update_user_meta( $user_id, ‘_sb_pkg_type’, ‘free’ ); } // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)