WordPress: Different post from custom post type everyday

I have a custom post type to display a single quote. Right now I have it set to random, but is it possible to have a WordPress loop that displays a random post but only changes once per day? So basically having a quote of the day post type. I see plugins for a quote of the day but these all pull from an external feed.

Related posts

3 comments

  1. Found a post scheduling plugin that let me recycle my quotes posts so that they can be randomized daily:

    Auto Post Scheduler

    Basically, I set the post schedule to 24 hours, set the post type to my custom post type, changed the eligible posts to published, checked randomize, and set the minimum age to 48 hours which I think should prevent the same post from being used two days in a row.

  2. You can create your own. The only thing you need is a plugin that displays posts (like this one), then to make a formula to pick a random post each day and you can set this script to run once per day (usually those type of automations are triggered from visitors).
    Useful links:
    Function: get_posts
    Function: wp_cron

  3. Try to use following code:-
    
        if ( false === ( $quotes = get_transient( 'random_quote' ) ) ) {
    
    
    // It wasn't there, so regenerate the data and save the transient
    $args = array(
     'post_type' => 'School',
     'orderby'   => 'rand',
     'limit' => 1,
     'posts_per_page' => '1');
    $quotes = get_posts( $args );
    set_transient( 'random_quote', $quotes, DAY_IN_SECONDS);
    foreach ( $quotes as $post ) { 
    setup_postdata( $post ); 
    <a href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a>
     <?php 
      echo $post->post_content;
       ?>
    <?php
       } 
    wp_reset_postdata();
        ?>
    

Comments are closed.