Keep in mind that if you leave this on the init action, this will occur on every page load. If you only want this to occur once or during another action, you’ll need to change this.
This will also timeout if you try to execute this on too many posts.
function update_my_metadata() {
$args = array(
'post_type' => 'post', // Only get the posts
'post_status' => 'publish', // Only the posts that are published
'posts_per_page' => -1, // Get every post
);
$posts = get_posts( $args );
foreach ( $posts as $post ) {
global $wpdb;
$number_one = $wpdb->get_var( $wpdb->prepare( "SELECT Number_1 FROM {$wpdb->prefix}table_help_i WHERE id_help_i = %d", $post->ID ) );
$number_two = $wpdb->get_var( $wpdb->prepare( "SELECT Number_2 FROM {$wpdb->prefix}table_help_i WHERE id_help_i = %d", $post->ID ) );
if ( ! empty( $number_one ) ) {
update_post_meta( $post->ID, 'your_meta_key_name', $number_one );
}
if ( ! empty( $number_two ) ) {
update_post_meta( $post->ID, 'your_meta_key_name', $number_two );
}
}
}
add_action('init', 'update_my_metadata');