Skip to content

Instantly share code, notes, and snippets.

@keefyhub
Created March 20, 2019 12:08
Show Gist options
  • Select an option

  • Save keefyhub/84e1f9a5f4f69f7eb26f92fbb2fa3c85 to your computer and use it in GitHub Desktop.

Select an option

Save keefyhub/84e1f9a5f4f69f7eb26f92fbb2fa3c85 to your computer and use it in GitHub Desktop.
Set random images from library
$args = [
'post_type' => 'post',
'posts_per_page' => -1
];
$results = new WP_Query($args);
while ($results->have_posts()): $results->the_post();
$images = [
793,
734,
722,
367
];
$image = $images[array_rand($images)];
update_post_meta($post->ID, 'listing_image', $image);
update_post_meta($post->ID, '_listing_image', 'field_image_32dac18920718ed6498d3c5e31fcdfd3');
endwhile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment