Hi , i am trying to set the post for 24 hours and with it will be changed

SIMPLE CODE

$args = [
‘posts_per_page’ => 1,
‘orderby’ => ‘rand’,
‘post_type’ => ‘post’,
‘ignore_sticky_posts’ => true,
];
$r= new WP_Query( $args );

if( $r->have_posts() )
{
while( $r->have_posts() )
{
$r->the_post();
if ( has_post_thumbnail() ) {
echo ‘ID). ‘”>’; the_post_thumbnail(); echo ‘ ‘;
}
the_title();
the_Excerpt();
}

}
else
{
_e( ‘Sorry no posts found!’ );
}
}


i also used the transient API but didn’t get any help , code with transient is

$args = [
‘posts_per_page’ => 1,
‘orderby’ => ‘rand’,
‘post_type’ => ‘post’,
‘ignore_sticky_posts’ => true,
];
$q= new WP_Query( $args );

set_transient( $r, $q, 28800 );

$r = get_transient($code);

if( $r->have_posts() )
{
while( $r->have_posts() )
{
$r->the_post();
if ( has_post_thumbnail() ) {
echo ‘ID). ‘”>’; the_post_thumbnail(); echo ‘ ‘;
}
the_title();
the_Excerpt();
}

}
else
{
_e( ‘Sorry no posts found!’ );
}

Read more here: Hi , i am trying to set the post for 24 hours and with it will be changed

Leave a Reply

Your email address will not be published. Required fields are marked *