Created
March 20, 2019 12:08
-
-
Save keefyhub/84e1f9a5f4f69f7eb26f92fbb2fa3c85 to your computer and use it in GitHub Desktop.
Set random images from library
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
| $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