Accessing $post global on a custom post type archive page


I have a custom post type called projects, and its archive is at /projects, on the archive page I get notices Notice: Trying to get property of non-object every time I try to access the $post i.e. $post->post_name. Is this intended behaviour? Should I just accept that and always check the availability of $post before using it?

if (!empty($post)) {
    // Do something with $post
any_h 2 years 2020-01-11T08:38:45-05:00 0 Answers 76 views 0

Leave an answer