title: Wordpress - How to schedule function to run every 48 hours
body: <p>I have a series of quotes saved in my database, and I want a singe, random quote to be pulled from the database and displayed on my site every 48 hours.</p>
  
  <p>I've found code for scheduling this to happen using a custom cron scheduled event for every 48 hours. However, I'm assuming I'm implementing it incorrectly because although a single random quote is showing up on the site, it is switching to a new random quote every time the page is refreshed, as opposed to once every 48 hours.</p>
  
  <pre><code>function quote_custom_cron_schedule( $schedules ) {
  $schedules['every_two_days'] = array(
      'interval' =&gt; 172800, // Every 48 hours
      'display'  =&gt; __( 'Every 48 hours' ),
  );
  return $schedules;
  }
  add_filter( 'cron_schedules', 'quote_custom_cron_schedule' );
  
  //Schedule an action if it's not already scheduled
  if ( ! wp_next_scheduled( 'quote_cron_hook' ) ) {
  wp_schedule_event( time(), 'every_two_days', 'quotes_cron_hook' );
  }
  
  //Hook into that action that'll fire every 48 hours
   add_action( 'quotes_cron_hook', 'quotes_cron_function' );
  
  //Function that executes via cron
  function quotes_cron_function() {
  $args = array(
  'post_type' =&gt; 'quote',
  'orderby' =&gt; 'rand',
  'posts_per_page'=&gt; 1,
  );
  
    $quotes = new WP_Query( $args );
    $quotes_output = '';
  
    if( $quotes-&gt;have_posts() ):
      while ( $quotes-&gt;have_posts() ) : $quotes-&gt;the_post();
        $quotes_title = get_the_title();
        $quotes_content = get_the_content();
        $quotes_output .= '&lt;div id="quote"&gt;&lt;p&gt;&amp;quot;' . $quotes_content . '&amp;quot;&lt;/p&gt;&lt;p class="quote-name"&gt;' . $quotes_title . '&lt;/p&gt;&lt;/div&gt;';
      endwhile;
    else:
        $quotes_output = '';
    endif;
  
    wp_reset_postdata();
    echo $quotes_output;
  }
  </code></pre>
  
  <p>I then have the following in my header.php file:</p>
  
  <pre><code>&lt;?php do_action( 'quotes_cron_hook' ); ?&gt;
  </code></pre>
  
  <p>This is executing the function, but it executes every time the page is refreshed. I need the function to wait 48 hours before changing the quote again. I feel like I'm probably missing something simple here.</p>