Created
April 8, 2015 15:47
-
-
Save Dimasmagadan/102bcfad9a83a2d641eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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