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