Get author Meta for particular user inside the loop

The function get_the_author_meta(‘ID’) will return the ID of the author for the current post. That means this line should work. get_avatar( get_the_author_meta( ‘ID’ ), 120); This will not work get_avatar( get_the_author_meta( ‘4’ ), 120); Because you are trying to get a property named ‘4’ inside the user object and that property doesn’t exist. If you … Read more

Read array in php?

Fastest way would be something like this: $fruit_id = get_user_meta($user_id, ‘fruit’, true); //returns 1 $display_fruit = some_fruits($fruit_id); //will return ‘Apple’

Does meta-data need to be sanitized?

Yes, it’s a good practice to sanitize input and escape output. It’s important to use the correct function, though, so that you don’t inadvertently mess up your data. Since it’s for a URL, use esc_url_raw() (it is specifically for db usage). (Note: it may seem odd using a function with the “esc_” stem for sanitizing, … Read more

Displaying field value in new column in users view on wordpress

Use this function to register a new column in the users table: function users_custom_columns( $column ) { $column[‘security_answer’] = ‘Security Answer’; return $column; } add_filter( ‘manage_users_columns’, ‘users_custom_columns’ ); And this function to display the new custom column: function display_users_custom_columns( $val, $column_name, $user_id ) { switch ($column_name) { case ‘security_answer’ : return get_user_meta( $user_id, ‘meta_key’, true); … Read more

get_results not returning anything

$wpdb->get_results() returns an array on success, so you can’t simply echo $result;. Instead, you can use foreach to loop through the results and display whatever the data that you want to display: $results = $wpdb->get_results( $q ); foreach ( $results as $row ) { echo $row->meta_value . ‘<br />’; } But I can see that … Read more

Difference between last_name and user_lastname

Short answer to “Which property am I supposed to use“: Use first_name and last_name. Longer answer: The properties first_name, user_firstname, last_name and user_lastname are defined in the WP_User class, and despite the different names (i.e. one with user_ and the other without that prefix): Both first_name and user_firstname use the value of the first_name meta. … Read more

Shortcode to update user meta

Basically, you can’t show the button and update the meta at the same moment. This has to be done in two separate requests as follows: Show the button whereever you want. It needs to be a form that submits to the same page (or an ajax call to another URL, but let’s keep it simple … Read more

How to combine two get_users() array?

Edit: to clarify, the answer to How can I merge them together for results? Is that you really can’t, not without a lot of custom SQL and using filters. The complexity of going that route far outweighs any perceived benefits and wouldn’t be very future-proof. I’d recommend using the solution below and putting it all … Read more