Created
May 24, 2023 16:34
-
-
Save lichtmetzger/4c91bb1c16a2ef442d29bc288c52d58e to your computer and use it in GitHub Desktop.
Copy old meta fields into new meta fields
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 | |
$args = array( | |
'post_type' => 'events', // Adjust post type if needed | |
'posts_per_page' => -1, // Retrieve all posts | |
); | |
$posts_query = new WP_Query($args); | |
if ($posts_query->have_posts()) { | |
while ($posts_query->have_posts()) { | |
$posts_query->the_post(); | |
$post_id = get_the_ID(); | |
// Get old general event date | |
$startTime = get_post_meta($post_id, 'event_date', true); | |
// Set it as new start date | |
update_post_meta($post_id, 'event_date_start', $startTime); | |
} | |
// Restore original post data | |
wp_reset_postdata(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment