I'm a new user of Stack Overflow and have very basic PHP knowledge.
I am coming across the PHP notice of Trying to get property 'ID' of non-object
I am using PHP 7.3, WordPress and ACF to set a custom post type to set a post status to draft after my closing date has past.
I'm getting the error in the error_log in public_html
PHP Notice: Trying to get property 'ID' of non-object in public_html/assets/themes/gig/functions.php on line 979
if ($expireTransient = get_transient($post->ID) === false) {
PHP Notice: Trying to get property 'ID' of non-object in public_html/assets/themes/gig/functions.php on line 980
set_transient($post->ID, 'set for 1 minutes', 1 * MINUTE_IN_SECONDS );
The code is set in my functions.php
file within my WordPress theme folder, I do not have PHP logging enabled
Can anyone help to correct the PHP notice
if ($expireTransient = get_transient($post->ID) === false) {
set_transient($post->ID, 'set for 1 minutes', 1 * MINUTE_IN_SECONDS );
$today = date('Ymd', current_time('timestamp', 0));
$args = array(
'post_type' => 'vacancies',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'closing_date',
'value' => $today,
'compare' => '<='
)
)
);
$posts = get_posts($args);
foreach( $posts as $post ) {
if(get_field('closing_date', $post->ID)) {
$postdata = array(
'ID' => $post->ID,
'post_status' => 'draft'
);
wp_update_post($postdata);
}
}
}