Querying Email Addresses for a List of Users with Same Last Name?

Hi @Holidaymaine: Here’s the query you are looking for: <?php include( ‘../wp-load.php’ ); $sql =<<<SQL SELECT DISTINCT u.user_email AS user_email, um.meta_value AS user_lastname FROM {$wpdb->users} AS u LEFT JOIN {$wpdb->usermeta} AS um ON u.ID = um.user_id LEFT JOIN {$wpdb->posts} AS p ON u.ID = p.post_author LEFT JOIN {$wpdb->term_relationships} AS tr ON p.ID = tr.object_id LEFT … Read more

Adding Custom User Profile data based upon Categories

here is an example //create the user category fields add_action( ‘show_user_profile’, ‘add_user_categories’ ); add_action( ‘edit_user_profile’, ‘add_user_categories’ ); function add_user_categories($user ){ ?> <table class=”form-table”> <tr> <th><label for=”user_categories”><?php _e(“User categories”); ?></label></th> <td> <?php $data = get_the_author_meta( ‘user_categories’, $user->ID ); $args = array( ‘hide_empty’ =>0, ‘taxonomy’=> ‘category’); $categories= get_categories($args); if ($categories){ foreach ( $categories as $category ){ if(in_array($category->term_id,(array)$data)) … Read more

wp_get_current_user in custom file returns 0

The problem with your code is that you want to get current user to early. wp_get_current_user is using global current_user variable. But this variable isn’t set from the beginning. And if you want to use this function straight in the script file, then it’s to early. You should wait for init action to get current … Read more

Searching user meta using WP_User_Query

Try this: $yoursearchquery = ‘This is my search’; $users = new WP_User_Query(array( ‘search’ => $yoursearchquery, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘shoe_size’, ‘value’ => $yoursearchquery, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘shoe_color’, ‘value’ => $search_operation, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘shoe_maker’, ‘value’ => $yoursearchquery, ‘compare’ => ‘=’ ) ) … Read more

Where to Store Custom User Fields

I know this question is very old, but I wanted to share my experience with working with large databases and storing custom user data. Basically wp_usermeta is the default and easiest option to store user meta and it works really well for smaller databases, where you might want to store a few extra fields for … Read more