Querying specific table row by current user login

Welcome! WordPress already have a table for users. Also, there is another table named usermeta that will allow you to save extra information for users. There are some functions that allow developers to get information from user and usermeta tables without using custom database queries. add_user_meta update_user_meta delete_user_meta get_user_meta Solution: As mentioned in the question, … Read more

Web app vs CMS backend

The idea of birgire is interesting but this can already be done with a single post per user. Create users with the role “Contributor” and then each user create a post with this content button 1 text a sentence, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor … Read more

What’s the correct way to add capabilites to user roles?

The best place to add this would be in the plugin’s activation hook. You can either call the dynamic activate_{$plugin} hook, or better yet use the provided register_activation_hook method. Using your code example above – something like this would be what you’re looking for: register_activation_hook( __FILE__, function() { $role = get_role( ‘editor’ ); $role->add_cap( ‘edit_booked_appointments’, … Read more

How to set all external links from a certain user to “nofollow”?

You want to try something like this (untested): // Nofollow in content $author_id = get_the_author_meta( ‘ID’ ); add_filter(‘the_content’, ‘my_nofollow’); function my_nofollow($content) { //return stripslashes(wp_rel_nofollow($content)); return preg_replace_callback(‘/<a[^>]+/’, ‘my_nofollow_callback’, $content); } function my_nofollow_callback($matches, $author_id) { $link = $matches[0]; $site_link = get_bloginfo(‘url’); if ($author_id === 4) { if (strpos($link, ‘rel’) === false) { $link = preg_replace(“%(href=\S(?!$site_link))%i”, ‘rel=”nofollow” $1’, … Read more

Author comment count in author page

all you have to do is to add an param: /* user commnet count */ function get_comment_count( $user_ID ) { global $wpdb; $count = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE user_id = %d “, $user_ID ) ); return $count; } <?php echo get_comment_count( <USER_ID> ); ?> PS. I’ve added some proper escaping in your … Read more

how to set default update_user_meta values wordpress

You can use the user_register action to run your user meta update when a user registers. /** * Sets the user meta key ‘_sb_pkg_type’ to ‘free’ when a user registers. * * @param int $user_id ID for the user who has registered. */ function wpse_update_user_meta_pkg_type( $user_id ) { update_user_meta( $user_id, ‘_sb_pkg_type’, ‘free’ ); } // … Read more

WordPress current month users

You can use the get_users function with date_query ! $month_users = get_users(array( ‘date_query’ => array( array( ‘after’ => ‘first day of this month’, ‘before’ => ‘last day of this month’, ‘inclusive’ => true ), ), )); if(!empty($month_users)) { foreach($month_users as $k => $v) { echo ‘User : ‘.$v->display_name.'<br>’; } }

How to get users by specific ID’s WordPress

To get a list of users by their IDs you simply need to add the include argument to your query; $args [ ‘include’ => [ 1, 2, 3, 4 ], // Get users of these IDs. ‘fields’ => [ ‘ID’, ‘user_email’, ‘display_name’, ‘user_url’ ], ]; $users = get_users( $args ); You don’t need to use … Read more

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