function quotes_shortcode() {
if ( false === ( $quotes = get_transient( 'random_quote' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
$args = array(
'post_type' => 'quotes',
'orderby' => 'rand',
'fields' => 'id',
'posts_per_page' => '1'
);
$quotes = get_posts( $args );
//Now we store the array for one day.
//Just change the last parameter for another timespan in seconds.
$seconds_until_next_day = strtotime('tomorrow') - time();
set_transient( 'random_quote', $quotes, MINUTE_IN_SECONDS );
}
foreach ( $quotes as $posts ) : setup_postdata( $posts );
?>
<div class="quote_container">
<em><?php the_content(); ?> - <p><?php the_title(); ?></p></em>
</div>
<?php
endforeach;
wp_reset_postdata();
}
add_shortcode('random_quotes','quotes_shortcode');
Я создал шорткод WordPress для отображения случайной цитаты в день, содержание цитаты, кажется, отображается нормально, но заголовок неверный, так как он получает заголовок страницы или сообщения, что шорткод вставлен в.