Skip to content

Commit

Permalink
Merge pull request #138 from wikitongues/main
Browse files Browse the repository at this point in the history
Staging deploy
  • Loading branch information
FredericoAndrade authored Sep 2, 2024
2 parents 05f599c + 794617a commit 5e64660
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions includes/update-videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,59 @@ function update_video_featured_language_iso_codes($post_id) {
function trigger_save_post_for_all_videos() {
// Check for a custom admin action
if (isset($_GET['trigger_save_post']) && $_GET['trigger_save_post'] == 'true') {
// Get all posts of post type 'videos'
// Log the start of the operation
error_log('Triggering save_post for all videos...');

// Initialize page number
$paged = 1;

// Define the query arguments for retrieving 'videos' posts
$args = array(
'post_type' => 'videos',
'posts_per_page' => -1, // Get all posts
'posts_per_page' => 50, // Get 50 posts at a time
'post_status' => 'any', // Include all post statuses if needed
'paged' => $paged, // Start from the first page
);

$video_posts = get_posts($args);
// Perform the query in a loop to handle pagination
while (true) {
// Log the current page being processed
error_log('Processing page: ' . $paged);

// Create a new WP_Query instance
$query = new WP_Query($args);

// If no posts are found, break the loop
if (!$query->have_posts()) {
error_log('No more posts found. Ending process.');
break;
}

// Loop through the posts
while ($query->have_posts()) {
$query->the_post();

// Get the current post ID
$post_id = get_the_ID();

if ($video_posts) {
foreach ($video_posts as $post) {
// Trigger save_post by updating the post
wp_update_post(array('ID' => $post->ID));
wp_update_post(array('ID' => $post_id));

// Log the updated post ID
error_log('Updated post ID: ' . $post_id);

// Reset the global post data to free up memory
wp_reset_postdata();
}
echo '<div class="notice notice-success"><p>' . count($video_posts) . ' video records updated.</p></div>';
} else {
echo '<div class="notice notice-warning"><p>No video records found.</p></div>';

// Increment the page number
$paged++;
$args['paged'] = $paged; // Update the query for the next page
}

// Log the completion of the operation
error_log('Done processing all video posts.');
}
}
add_action('admin_notices', 'trigger_save_post_for_all_videos');
?>
?>

0 comments on commit 5e64660

Please sign in to comment.