Skip to content

Instantly share code, notes, and snippets.

@Dimasmagadan
Created April 8, 2015 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimasmagadan/102bcfad9a83a2d641eb to your computer and use it in GitHub Desktop.
Save Dimasmagadan/102bcfad9a83a2d641eb to your computer and use it in GitHub Desktop.
<?php
if ( false === ( $vip_loop = get_transient( 'last_vips' ) ) ) {
$args = array(
'posts_per_page' => 100, // берем либо все посты, либо какое-то большое число
// по желанию отключаем лишнее
// 'no_found_rows' => true,
// 'cache_results' => false,
// 'update_post_term_cache' => false,
// 'update_post_meta_cache' => false,
);
$vip_loop_data = new WP_Query( $args );
if ($vip_loop_data->have_posts()) {
while ($vip_loop_data->have_posts()) : $vip_loop_data->the_post();
// сохряняем нужное в переменную $vip_loop в виде массива
// например так
$vip_loop[]['title'] = get_the_title();
endwhile;
}
wp_reset_postdata();
$exp_time= 43200;
set_transient( 'last_vips', $vip_loop, $exp_time );
}
if($vip_loop){
// перемешиваем
shuffle($vip_loop);
$i=0;
foreach ($vip_loop as $post) {
// и выводим
echo $post['title'];
if($i==10){
break;
}
$i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment