Rather than hooking into init or wp_load, here is a snippet you can drop into functions.php or on a theme file. I put it behind a $_GET so that you can only hit it once and when you are ready. Something like https://domain.com/page/?update_post_meta
// Hide it from the public
if(isset($_GET['update_post_meta'])){
// Let's query all of the product post_type.
$product_args = array(
'post_type' => 'product',
'posts_per_page' => -1
);
$product_query = new WP_Query($product_args);
while( $product_query->have_posts()): $product_query->the_post();
$title_length = strlen($post->post_name);
// - Update the post's metadata.
if ( $post->post_name ) {
update_post_meta( $post->ID, '_product_title_length', $title_length );
}
endwhile;
}
If you want to run this on specific posts you have not edited already, you can update the $product_args
array to have a date range in it.
Hope this helps!!