Last active
August 29, 2015 14:12
-
-
Save alexkalh/b9b8d0137404a4b21dfb to your computer and use it in GitHub Desktop.
Auto set featured image for post by random
This file contains hidden or 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 | |
$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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can read full tutorial on my blog http://colourstheme.com/2015/01/auto-set-featured-image-for-post-by-random/