Guest User

Untitled

a guest
Apr 2nd, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. function update_modified_date_on_publish($new_status, $old_status, $post) {
  2. // Only update if transitioning from 'future' (scheduled) to 'publish'
  3. if ($old_status === 'future' && $new_status === 'publish') {
  4. // Update the post's modified date to match the published date
  5. wp_update_post(array(
  6. 'ID' => $post->ID,
  7. 'post_modified' => current_time('mysql'),
  8. 'post_modified_gmt' => current_time('mysql', 1),
  9. ));
  10. }
  11. }
  12.  
  13. add_action('transition_post_status', 'update_modified_date_on_publish', 10, 3);
  14.  
Advertisement
Add Comment
Please, Sign In to add comment