Created
December 8, 2013 12:04
-
-
Save wpexplorer/7856523 to your computer and use it in GitHub Desktop.
Automatically set featured image to all posts in a post type
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
| add_action('init','set_post_thumbnails'); | |
| function set_post_thumbnails() { | |
| // Query args | |
| $args = array( | |
| 'post_type' => 'testimonials', | |
| 'posts_per_page' => '-1' | |
| ); | |
| // Run query | |
| $query = new WP_Query( $args ); | |
| // Open query loop | |
| if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); | |
| set_post_thumbnail( get_the_ID(), '2733' ); | |
| // Close query loop | |
| endwhile; endif; | |
| wp_reset_postdata(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment