Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created July 11, 2019 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/42d247c6d757069d19a34cfc3e725d5e to your computer and use it in GitHub Desktop.
Save billerickson/42d247c6d757069d19a34cfc3e725d5e to your computer and use it in GitHub Desktop.
<?php
/**
* Bulk update posts
*
*/
function be_bulk_update_posts() {
$loop = new WP_Query( array(
'posts_per_page' => 100,
'meta_query' => array(
array(
'key' => 'be_featured_image_width',
'compare' => 'NOT EXISTS',
) )
) );
if( $loop->have_posts() ): while( $loop->have_posts() ): $loop->the_post();
if( has_post_thumbnail() ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
if( !empty( $image[1] ) )
update_post_meta( get_the_ID(), 'be_featured_image_width', intval( $image[1] ) );
}
endwhile; endif; wp_reset_postdata();
}
add_action( 'wp_footer', 'be_bulk_update_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment