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 make wordpress use a non-wordpress users table?

I figured it out. All I did was create a VIEW mapping the columns like this: CREATE VIEW wp_users (ID, user_login, user_pass, user_nicename, user_email, user_url, user_registered, user_activation_key, user_status, display_name) AS SELECT u.user_id, u.username, u.password, u.first_name, u.email, ”, u.date_created, ”, 0, u.display_name FROM Users u;

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

check for duplicate user meta data before updating

You can check duplicate user meta using sql query.in below code if duplicate record found of other users then it will display error message and not update value. add below code in active theme’s functions.php file. function save_cust_user_profile_fields( $user_id ) { if ( isset($_POST[‘social_number’]) ) { global $wpdb; $social_number = $_POST[‘social_number’]; # query to check … 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