Use this function:
function user_id_exists($user){
global $wpdb;
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users WHERE ID = %d", $user));
if($count == 1){ return true; }else{ return false; }
}
Usage:
if(user_id_exists(1)){
//it does exists
} else {
//it doesn't
}
Related Posts:
- Adding fields to the “Add New User” screen in the dashboard
- Use author author display name in permalink structure for pages and posts
- Get a list of all available fields in the User Profile
- Logout redirect to current page – function
- How to paginate the get_users function?
- How to display random users with avatars
- How to manually activate user in dashboard only by admin
- Add new user : make the fields First Name and Last name required
- wp_delete_user with username
- Change labels on ‘Nickname’ and ‘Biographical Info’ in user-edit.php
- Order get_users() by last login date. Is it possible?
- How can I tell when a user is logged in?
- how to get and display logged in user’s recently read posts
- Displaying a random user with a shortcode
- How to update BuddyPress xprofile fields programmatically? [closed]
- How to detect first visit of a user?
- Can I pass two roles to the function get_users?
- How can I add an image field to BuddyPress Extended Profile Fields? [closed]
- Create dropdown of users in admin dashboard
- password protected post policy
- Remove the deleted users avatar from list
- Get Current User info using wp_localize_script, in functions.php
- How to add custom fields to my custom registration form
- create shortcode to list users with specific meta key value
- Don’t delete a page if it holds users
- How to make custom column Admin>Users sortable?
- Execute a ultimate member action when user role is updated
- Filter out other users comments. Visualize only own comments and editor role users’ comments
- Force to use STRONG users password and implement rule to prevent REUSE [closed]
- Change label for registration Fields
- Condition OR for current user ID
- How to Use Global Variables Inside Header and Footer
- Secondary Menu and Logged In Users
- Why get_user_by() doesn’t work in my code?
- Filter to wp_list_authors
- How to add array [closed]
- Add Link to Users List (Backend) to open each users front-end profile
- Suggest Users basing on User taxonomy
- Showing user profile data on front-end
- Modify function to only return values for the user that’s logged in
- loginout function customization
- User meta and public function security
- call wp_insert_user in custom class doesnt work
- Get users with different roles and call function on each of them (user_meta)
- Show errormessages on wrong username/password on custom loginform?
- How can I show different content for different user-levels?
- Custom user role still showing up after deletion, ideas?
- referencing the current user in a page i created in wordpress
- Show metadata in users.php – wordpress
- Deleting guests profile users after 1.5 hours
- wp_get_current_user return ID = 0 when used outside of wordpress, such as webhook / fulfillment dialogflow
- Allow user only create specific tags
- Add Change role button for list of user in an event
- get_current_user_id() always return 0 in if else statement
- Show users last read posts for each user?
- How to add number to wordpress count function?
- get USER ID in functions.php using user_register action
- Whats the proper way to add a new user via a front end form?
- sort by date in users
- How to load scripts/styles specific for a page
- Is there a is_user_logged_in() for multisite?
- Perform an action when post is updated/published
- Sort posts by Date (DESC) and by Title (ASC)
- How to remove row-actions from pages table?
- Using wp_get_nav_menu_items() to list children of children pages
- wp_is_mobile function
- Get user id from email?
- Custom menus displaying all pages instead of set pages
- Change a sidebar name?
- CSS stylesheet not loading
- Generate permalinks
- Best Practice for Syncing Local Development With Staging Development [closed]
- How to use max and min values of custom fields
- When using wp_enqueue_script(); in a theme why don’t we use add_action?
- Batch update menu_order attribute alphabetically
- How to create function from code?
- How to use Internationalized human_time_diff() function in Chinese?
- How to add ‘data-caption’ inside an anchor tag
- Search filter by Post title OR Meta Title Value [duplicate]
- Why is functions.php file in child not initializing and over-writing parent?
- How to add custom JavaScript in functions?
- srcset and custom field get_post_meta and wp_get_attachment_url
- Extending a custom framework built into WordPress to automatically turn the ‘Search Engine Visibility’ setting ON / OFF, dependant on environment
- Add Adsense code between job listings – wp job manager plugin
- How can I change the size of the text in Word Press
- How to hightlight all ancestor menu items of a child page NOT displayed in menu
- Show admin page, only if function is being used
- How to apply the ‘current_page_item’ class to an archive page in `wp_list_pages()`?
- Best practice to call a function from a button-link?
- Disable wordpress update notification
- Extend WordPress Audio Widget to accept HLS (.m3u8) URLs
- locking content with overlay/pop up ads
- delete_user_meta for user in spesific group
- Remove Featured Images from Posts Older Than a Certain Date
- Mail function not working with user accounts
- Conditionally write open graph meta property in header
- Using array page name together with page id to deregister script
- Modifying Page-Links format
- Give a function a unique ID
- how to handle multiple forloop?