WP_Post Object vs stdClass Object

I have two results , one with WP_Post Object and other is stdClass Object. All contains same data. How do I differentiate them?

Result 1 :-

Read More
WP_Post Object
(
    [ID] => 952
    [post_content] =>  
    [post_title] => 
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
)

Result 2 : –

stdClass Object
(
    [ID] => 952
    [post_content] =>  
    [post_title] => 
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
)

Related posts

2 comments

  1. You can try to use instanceof

    Like this:

    if($obj instanceof WP_Post)
    

    I am not sure if it is a valid approach, but I have seen this used in some plugins and projects. So as a possible approach it might work

Comments are closed.