据我所知,您希望得到相同的结果,但将其顺序随机化。因此,您需要对结果进行洗牌。使用起来很简单shuflle()
PHP函数。但该函数需要数组,而不是对象。
您可以将对象从WP\\u查询转换为数组,或者,我认为最好使用get_posts()
而不是WP\\U查询。
$args = array(
// Arguments to get posts
);
$posts = get_transient ( "your-transiente-name" );
if( $posts === false ) {
$posts = get_posts( $args );
set_transient( "your-transiente-name", $posts, "the-expiration-time" );
}
// Shuffle the $post array
$posts = shuffle( $posts );
foreach( $posts as $post ) {
setup_postdata( $post );
// Standard loop stuff
}
wp_reset_postdata();