您可以使用以下代码:
$today = getdate();
$randompost = array(
\'date_query\' => array(
array(
\'before\' => \'3 days ago\',
\'after\' => array(
\'year\' => $today[\'year\'],
\'month\' => $today[\'mon\'],
\'day\' => $today[\'mday\'],
),
),
),
\'numberposts\' => 2,
\'type\' => \'news\',
\'orderby\' => \'rand\',
);
$rand_posts = get_posts( $randompost );
if ( $rand_posts ) {
foreach ( $rand_posts as $post ) :
setup_postdata( $post );
?>
<!-- Your Markup Here -->
<?php
endforeach;
wp_reset_postdata();
}
?>
查看更多详细信息
here