Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Created December 8, 2013 12:04
Show Gist options
  • Select an option

  • Save wpexplorer/7856523 to your computer and use it in GitHub Desktop.

Select an option

Save wpexplorer/7856523 to your computer and use it in GitHub Desktop.
Automatically set featured image to all posts in a post type
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