Issue with foreach on duplicate meta_key’s

Here is an example of getting the user IDs, looping through each, grabbing a meta_key as an array, adding new values to it and remove old values, saving the meta back, then grabbing it again to loop through each item in the array for output. Array is just an example of duplicate keys. $user_query = … Read more

User Relationship

if I were you, I would use the wp_usermeta table. it is possible to add information to this table easily: add_user_meta(NEW_USER_ID, “PARENT_USER_ID”,USER_ID,true); USER_ID: the Id of top level user, (In your case id of user A) “PARENT_USER_ID”: some key that you could search and find result based on NEW_USER_ID: The Id of sub_user true: To … Read more

Get users primary blog URL in MultiSite

There’s actually a function for that: get_active_blog_for_user() https://developer.wordpress.org/reference/functions/get_active_blog_for_user/ $user_id = get_current_user_id(); $user_blog = get_active_blog_for_user( $user_id ); echo $user_blog->siteurl;

Displaying additional User Contact Information

This might help you out if you haven’t found an answer yet. /* BEGIN Custom User Contact Info */ function extra_contact_info($contactmethods) { unset($contactmethods[‘aim’]); unset($contactmethods[‘yim’]); unset($contactmethods[‘jabber’]); $contactmethods[‘facebook’] = ‘Facebook’; $contactmethods[‘twitter’] = ‘Twitter’; $contactmethods[‘linkedin’] = ‘LinkedIn’; return $contactmethods; } add_filter(‘user_contactmethods’, ‘extra_contact_info’); /* END Custom User Contact Info */ Displaying it: <a href=”https://wordpress.stackexchange.com/questions/32505/<?php the_author_meta(“facebook’, $current_author->ID); ?>”></a> http://thomasgriffinmedia.com/blog/2010/09/how-to-add-custom-user-contact-info-in-wordpress/

Display site admin profile fields in header.php

Ok I figured a way to do it. If anyone else is interested, here’s the code. It first gets the user id of the admin of the blog, and then it uses the id to pull the meta from the profile fields. For one field — <?php $thisblog = $current_blog->blog_id; $user_id_from_email = get_user_id_from_string( get_blog_option($thisblog, ‘admin_email’)); … Read more

How to add country drop down menu to the user profile?

Try this /* Save selected data */ add_action( ‘personal_options_update’, ‘save_user_fields’ ); add_action( ‘edit_user_profile_update’, ‘save_user_fields’ ); function save_user_fields( $user_id ) { if ( !current_user_can( ‘edit_user’, $user_id ) ) return false; update_usermeta( $user_id, ‘country’, $_POST[‘country’] ); } add_action( ‘show_user_profile’, ‘Add_user_fields’ ); add_action( ‘edit_user_profile’, ‘Add_user_fields’ ); function Add_user_fields( $user ) { ?> <h3>Additional Field</h3> <table class=”form-table”> <tr> <th><label … Read more

update_user_meta adding new rows in db for same key

Try this: global $current_user; $user_id = $current_user->ID; // current user ID $meta = get_user_meta( $user_id, ‘title’, ‘Manager’ ); // subject meta if($meta != ”) // updates meta if exists update_user_meta($user_id, ‘title’, ‘Manager’); else // creates new meta if not exists add_user_meta($user_id, ‘title’, ‘Manager’);

How to get top 10 user is based on user meta value

I guess you can do with get_users, something like: $topusers = get_users( array ( ‘meta_key’ => ‘todayuserclicks’, ‘meta_value’ => ”, ‘meta_compare’ => ‘!=’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘number’ => ’10’, ) );