check if post id exists wordpress

To check if a post ID exists in WordPress, you can use the get_post_status() function. Here are the steps:

  1. Use the get_post_status() function with the post ID as the parameter.
  2. The function will return the status of the post if it exists, or false if the post ID does not exist.
$post_id = 123; // Replace 123 with the actual post ID
if ( false !== get_post_status( $post_id ) ) {
    // Post ID exists
} else {
    // Post ID does not exist
}