-
-
Save billerickson/42d247c6d757069d19a34cfc3e725d5e to your computer and use it in GitHub Desktop.
This file contains 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
<?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