php – How to include support for all page types, calendar urls, archive, etc


I’m writing a plugin and I get this error when viewing calendar urls for example the calendar archive list on a wordpress site. I do not get the error on posts or pages, only get error when viewing a set of posts via calendar/archive/calendar url (example of what I mean by calendar url. -not an actual link-.). I assume the error means I am not including compatibility for other types of pages, like archives, urls showing sets by date, etc. I’m new to programming. Please give me any comments if you have any thoughts after seeing this portion of code. The error message is “Notice: Trying to get property ‘post_type’ of non-object” The code I am trying to write better:

$wp_the_query   = $GLOBALS['wp_the_query'];
$queried_object = $wp_the_query->get_queried_object();
$post_object    = sanitize_post( $queried_object );
$post_type      = $post_object->post_type;
$post_id        = $post_object->ID;

Angel Hess 1 month 2021-08-12T19:01:03-05:00 0 Answers 0 views 0

Leave an answer