Skip to content

Instantly share code, notes, and snippets.

@alexkalh
Last active August 29, 2015 14:12
Show Gist options
  • Save alexkalh/b9b8d0137404a4b21dfb to your computer and use it in GitHub Desktop.
Save alexkalh/b9b8d0137404a4b21dfb to your computer and use it in GitHub Desktop.
Auto set featured image for post by random
<?php
$begin_ID = 1;
$end_ID = 10;
$items = array();
for ($i = $begin_ID; $i <= $end_ID; $i++) {
$items[] = $i;
}
$posts = new WP_Query(array(
'post_type' => array('post'),
'posts_per_page' => -1
));
$index = 0;
while ($posts->have_posts()){
$posts->the_post();
set_post_thumbnail(get_the_ID(), $items[$index]);
if ($index == count($items) - 1)
$index = 0;
else
$index++;
}
wp_reset_postdata();
@alexkalh
Copy link
Author

alexkalh commented Jan 5, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment