Basically I want to automatically set an image randomly from a selection of about 3 or 4 images in my Media Library when someone posts a blog from a particular category. I've got this so far but it only sets one image for that category.
function default_category_featured_image() {
global $post;
$featured_image_exists = has_post_thumbnail($post->ID);
if (!$featured_image_exists) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment);
}}
else if ( in_category('49') ) {
set_post_thumbnail($post->ID, '2200');
wp_reset_postdata();
}
}
}
add_action('the_post', 'default_category_featured_image');
Is it possible to have more than one feature image randomly for each category?