How to get the post status from the post object of a custom post

When retrieving the post status of an article in a custom post type, you may not get the expected result if you try to retrieve it directly from the post object as follows

if ($post->post_status=='publish') { 

Instead, use the WordPress function get_post_status() with the post ID to get the status. An example of its use is shown below.

if (get_post_status($post->ID)=='publish') { 

This way, it is possible to get the exact post status.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top