Avoid to select/show a randomly queried post for a certain period of time (post of the day)

Question

I would like to present a randomly selected post on my homepage every day. I have already created a working query for this (I have set 60 seconds as time for testing purposes).

Now I’m looking for a solution that for a certain period of time (e.g. a month) the same posts are not shown again. So if a post is randomly selected and displayed, it should not be displayed again until after one month at the earliest.

function post_of_the_day( $query_args) {
    global $post;
    
    $rand = sprintf( 'RAND(%d)', floor( time() / 60 ) );
    $query_args = array(
            'post_type'     => 'custom_post_type',
            'orderby'       => $rand,
            'posts_per_page' => 1,
        );

     return $query_args;

     }
0
RaWa 2 months 0 Answers 17 views 0

Leave an answer