Set the publication date independent of the scheduled publication date

admin2025-06-04  2

  • I want to write a post today (2019-01-15)
  • I want to schedule the publication for the future (2020-09-03)
  • I want the published date to reflect when it was originally written - so it appears as example/2019/01/slug - or an arbitrary date in the past.

Can anyone suggest how I might do this?

  • I want to write a post today (2019-01-15)
  • I want to schedule the publication for the future (2020-09-03)
  • I want the published date to reflect when it was originally written - so it appears as example/2019/01/slug - or an arbitrary date in the past.

Can anyone suggest how I might do this?

Share Improve this question asked Jan 15, 2019 at 11:59 Terence EdenTerence Eden 1577 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I'm afraid it won't be possible without any coding, but... It shouldn't be so hard to achieve.

I would approach it this way:

  1. Schedule post for publication using native post date.
  2. Store the real publication date as some custom field.
  3. Add custom action to transition_post_status hook and replace the publish date with the one stored in custom field.

.

function replace_publish_date( $new_status, $old_status, $post ) {
    if ( 'publish' == $new_status && 'future' == $old_status ) {
        wp_update_post( array(
            'ID' => $post->ID, 
            'post_date' => get_post_meta( $post->ID, 'real_publish_date', true )
        ) );
    }
}
add_action( 'transition_post_status', 'replace_publish_date', 10, 3 );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749009629a315581.html

最新回复(0)