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

Search multiple meta keys at once

You’ll want to use the ‘meta_query’ argument of WP_Query ( http://codex.wordpress.org/Class_Reference/WP_Query ) Here’s a snippet that uses two separate meta key comparisons: $query_args = array( ‘post_type’ => ‘event’, ‘order’ => ‘ASC’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘_start_date’, ‘meta_query’ => array ( array( ‘key’ => ‘_start_date’, ‘value’ => $_start_of_month, ‘compare’ => ‘>’, ), array( ‘key’ => … Read more

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