LoginSignup
3
2

More than 5 years have passed since last update.

[WordPress] WP Post Branches で更新された元記事の公開日時を変更しない

Last updated at Posted at 2018-03-27

WP Post Branches

  • 公開された記事に対して「ブランチ」を作って指定日時(公開予定日時)で元の投稿を上書きするプラグイン
  • 上書きされるまで元の投稿はそのまま公開しておける

使い方はぐぐってください

元記事の公開日時も更新されてしまう問題

早い話プラグインの仕様な訳ですが、アーカイブなどで記事の順序が入れ替わるのでそれをやめたいわけです。

  • 元記事の更新日時をブランチ記事の公開日時にする
  • 元記事の公開日時は変更しない

フィルターフックがあるのでよしなに改変すればOK。
https://github.com/horike37/WP-Post-Branches/blob/master/wp-post-branches.php#L179

my_wpbs_draft_to_publish_update_post.php
add_filter( 'wpbs_draft_to_publish_update_post', 'my_wpbs_draft_to_publish_update_post', 10, 1 );
function my_wpbs_draft_to_publish_update_post( $new ) {

    // 元記事の更新日時をブランチ記事の公開日時にする
    $new['post_modified']      = $new['post_date'];
    $new['post_modified_gmt']  = $new['post_date_gmt'];

    // 元記事の公開日時は変更しない
    $old_id   = $new['ID'];
    $old_post = get_post( $old_id );

    $new['post_date']     = $old_post->post_date;
    $new['post_date_gmt'] = $old_post->post_date_gmt;

    return $new;
}

現場からは以上です。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2