There are many great code snippets in their Gitlab. You might find more on their…
Update some meta for all media library items
Only run this once! uncomment the „add_action“ then open site and then comment it out again. Watch your timeout depending on how many images you have.
/*
* Update ALL attachments metada with Width and Height
*
* Important: Run Only Once
*
*/
//add_action('admin_init','wpse_35680_run_only_once');
function wpse_35680_run_only_once()
{
global $wpdb;
$attachments = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_mime_type LIKE '%image%'" );
foreach( $attachments as $att )
{
list( $url, $width, $height ) = wp_get_attachment_image_src( $att->ID, 'full' );
update_post_meta( $att->ID, '_width', $width );
update_post_meta( $att->ID, '_height', $height );
}
}
Dieser Beitrag hat 0 Kommentare