Hot answers tagged

6

Clients get added by admins, clients have a parent child relationship with employees which makes filtering easy. So all we need to do is remove anything that doesn't have to do with employees and filter for employees with a certain meta value. First thing's first, whenever a new user is registered on the admin side of our CMS we will assign it a parent of ...


5

Both write their data in the “usermeta” table. User options stored in the usermeta table retain the wordpress table prefix e.g. wp_ whereas the user meta also stored in the usermeta table doesn't. User options support blog-specific options, useful in multisite. The user meta is based on the user id specific meta data like profile information. The ...


5

In layman terms there is no major difference! update_user_option() uses update_user_meta() internally. The only difference is update_user_option() prefix the option name with database table prefix + blog ID if you are in multisite and just table prefix if you are in single site installation. Take a look at the code of update_user_option() /** * Update ...


4

The rich_editing user option stores this check box value: wether or not do enable the visual editor for that particular user. If it's disabled then the content editor will look like this:


4

You forgot option 3 - Add a special table in which the pair (user,post id) will be the index. Ok I am not a MySQL person so maybe it is too extreme, but maybe having two tables one with users as index and one with posts will be even better. The thing about performance is that there are rarely absolute solutions for everybody at anytime, and the "best" ...


4

You're wanting to hide a user from WordPress in three places: The user list in the admin The count above that user list The user's author archive on the front-end As you mentioned, you've already solved item 1 and you've included the code for that. So, I'll provide the solutions for items 2 and 3. The user you want to hide is an administrator with a ...


3

In the core, the bottom input names are marked with the instance number, e.g. new_role (top) and new_role2 (bottom). Here are two approaches for a similar naming convention, namely course_section1 (top) and course_section2 (bottom): Approach #1 Since the $which variable (top,bottom) doesn't get passed to the restrict_manage_users hook, we could get around ...


3

What Caused the Problem The problem was that the restrict_manage_users action gets called twice: once ABOVE the Users table, and once BELOW it. This means that TWO select dropdowns get created with the same name. When the Filter button is clicked, whatever value is in the second select element (i.e. the one BELOW the table) overrides the value in the first ...


3

I tested your code in both Wordpress 4.4 and in Wordpress 4.3.1. With version 4.4, I encounter exactly the same issue as you. However, your code works correctly in version 4.3.1! I think this is a Wordpress bug. I don't know if it's been reported yet. I think the reason behind the bug might be that the submit button is sending the query vars twice. If ...


3

get_users() does not allow you to directly sort by whatever you like, but there are ways around it. The Codex for get_users() says: orderby - Sort by 'ID', 'login', 'nicename', 'email', 'url', 'registered', 'display_name', 'post_count', 'include', or 'meta_value' (query must also contain a 'meta_key' - see WP_User_Query). meta_value is a very powerful ...


3

Trying to detect when a UI was triggered, is indeed the wrong general approach (unless you want to tie to the UI). A proper one will be to hook on the user_register action. add_action( 'user_register', 'wpse223196_registration_save', 10, 1 ); function wpse223196_registration_save( $user_id ) { add_user_meta($user_id, 'score', 5); }


3

Register a collection post type to represent a single collection. You'll get permalinks and rewrite rules to resolve the requests for free. Insert a new collection post for a user when they create a collection, and save the chosen post IDs as an array in post meta. You can pass that array directly as post__in argument in a WP_Query instance to load the ...


2

There is no tax_query parameter for the WP_User_Query class. Since you've tagged the question with user-meta I can only assume you store the ID (or even the term name itself?) of a particular shop-category term as a user meta entry. In this case you would need something like this: // The 'WP_User_Query' arguments array $args = array( 'role' =&...


2

Maybe this will answer your question: (Note: Due to bug #23268, value was required for NOT EXISTS comparisons to work correctly prior to 3.9. You had to supply some string for the value parameter. An empty string or NULL will NOT work. However, any other string will do the trick and will NOT show up in your SQL when using NOT EXISTS. Need inspiration? ...


2

You probably haven't changed the display name, which is probably what is being displayed. "nicename" is used for the author's posts page url and not for display. UPDATE wp_users SET display_name = replace(display_name, @old_user, @new_user);


2

There's no built-in functionality to append meta values you'll need to do it manually. If you plan on adding multiple values I would suggest saving it as an array but it will serialize it in the database which will make it harder to run WP_Meta_Query on. $user_id = fav_authors_get_user_id(); $fav_author_id = 2; $author_list = get_user_meta( $...


2

You're close - just need to tweak your arguments: <?php echo get_user_meta( $customer_id, 'billing_phone', true ) ?> Just make sure $customer_id is the ID of the user - you probably want get_current_user_id() instead.


2

Roles First of all you need to register the 2 roles, look at add_role. When you register the role, you are free to assign any capability you want. Only be careful to add the roles when your theme / plugin is activated and possibly remove them (see remove_role) when it is disabled. Meta Data You can do the association using a meta entry like ...


2

Finally I found answer by myself. Let's explore it with two user meta's current_login, last_login.Lets see the code. //function for setting the last login function set_last_login($login) { $user = get_userdatabylogin($login); $curent_login_time = get_user_meta( $user->ID , 'current_login', true); //add or update the last login value for ...


2

This is a different Javascript solution that may be helpful for some people. In my case I simply removed the 2nd (bottom) select list entirely. I find that I never use the bottom inputs anyway... add_action( 'in_admin_footer', function() { ?> <script type="text/javascript"> jQuery(".tablenav.bottom select[name='course_section']")....


2

There is the action hook user_register that is called immediately after a user is added to the database. The user id is passed to the hook as an argument. You can use wp_insert_post to insert a new post in that action. You just need to get the relevant info from the user and add it to the post. You can add custom fields to the post you create by referencing ...


2

Alright, there's a few things that isn't standardized WordPress so I've put together a minimal script which I'll explain piece by piece. Hopefully clear things up for you by the time you get to the end. HTML Form Below is a very simple HTML form. We're going to use javascript to listen for submission and stop it from actually refreshing the page but that ...


2

If you are working with serialized data as your meta_value, that sucks, as Pieter suggested, it's best not to. However if there is no way around the serialization problem then I wonder if a meta_query using a compare value of LIKE might help... Example: //psuedo serialized data... (e.g. value of meta_key = fruits_user_like) //a:4:{i:0;s:5:"apple";i:1;s:6:...


2

Use this action hook found in buddypress/bp-xprofile/classes/class-bp-xprofile-profiledata.php do_action_ref_array( 'xprofile_data_after_save', array( $this ) ); You'll need to use the actual field_id for your xprofile description. This example assumes it is 25. You can get the field_idby going to wp-admin > Users > Profile Fields and clicking 'Edit'...


1

You didn't add any code (make sure you add your own code next time because nobody bothers to help you if we have to guess the problem) but Im pretty sure I know what's wrong. Straight out of the WordPress codex: echo get_avatar( $user_id_or_email, $avatar_size, $default_avatar, $alt_text, $args ); You have to echo it because get_avatar() doesn't ...


1

Might be because you are using a depreciated function for updating/adding the user meta (update_usermeta). You need to use update_user_meta function. WP Codex: https://codex.wordpress.org/Function_Reference/update_user_meta


1

BuddyPress does not store the avatar path in the database. It loads avatars using the directory path - usually .../wp-content/uploads/avatars/. For example, the full sized avatar for a member might be .../wp-content/uploads/avatars/1/ef1e70a512662ea4fdca5b2efb6f76ab-bpfull.jpg where 1 is the user_id. Check your BP installation to find the exact path to ...


1

In your author.php file, get the user metadata via get_user_meta(), then do an if statement of $user->roles == 'rivenditore', display the meta data as you desire, and then do an elseif $user->roles == 'installatori' statement with what you wish to display for users on other roles. EDIT: Code example as requested: // get author data $queried_object =...


1

Thanks yo Howdy_McGee, Here is working code. // Remove favorite authors from current users DB function fav_author_remove_user(){ check_ajax_referer( 'fav_authors_obj_ajax', 'security' ); $remove_this_author = $_POST['clicked_author_id']; if ( current_user_can( 'edit_posts' ) ){ $user_id = fav_authors_get_user_id(); $author_list ...


1

Here a code example with explanation in the comments: // First a check whether the use is logged in or not: if ( is_user_logged_in() ) { // The user is logged, retrieve the user id $user_ID = get_current_user_id(); // Now we have got the user's id, we can pass it to the function 'count_user_posts': echo 'Number of posts published by user: ' . ...



Only top voted, non community-wiki answers of a minimum length are eligible