下記のサイトを参考にWordpressで「公開済の記事を指定日時で予約更新する」に挑戦しましたが、私の環境では表示がうまくできなかったため、ちょういと調整しました。
元ソース:kzさんのサイト公開済の記事を指定日時で予約更新する
参考サイト:[WP] $post->post_contentで本文を取得したときにhtmlをしっかり取得する方法
うまく表示しなかったので修正メモ
「get_the_content()」と「->post_content」は、記事のテキスト情報しかとってこないようなので、参考サイトを元に下記の修正でhtmlをしっかり取得するように調整しました。
投稿もページでも動きました。
・テキストとアトリビュートの取得
「return get_the_content();」を「return the_content();」に変更
・テキストにthe_contentsのアトリビュートを適用
「return $revision->post_content;」を
「return $content = apply_filters(‘the_content’, $revision->post_content);」に変更
読み込み側はループ内の
the_content();を
echo my_get_content();に変更
調整後のfunction.php
[php]
ID, $fu_key, true);
if(!$update || ($update && $update <= $now))
//return get_the_content();
return the_content();
$args = array(
'order' => ‘DESC’,
‘orderby’ => ‘ID’,
‘post_parent’ => $post->ID,
‘post_type’ => ‘revision’,
‘post_status’ => ‘inherit’,
‘meta_key’ => $fu_key,
‘meta_value’ => $now,
‘meta_compare’ => ‘<='
);
if($revisions = get_children($args))
foreach($revisions as $revision)
//return $revision->post_content;
return $content = apply_filters(‘the_content’, $revision->post_content);
return ‘No content.’;
}
//meta_box追加
function my_meta_futureupdate_box(){
add_meta_box(‘my_meta_futureupdate_box’, ‘更新予定日時の指定’,
‘my_meta_futureupdate_html’, ‘post’, ‘normal’, ‘high’);
add_meta_box(‘my_meta_futureupdate_box’, ‘更新予定日時の指定’,
‘my_meta_futureupdate_html’, ‘page’, ‘normal’, ‘high’);
}
function my_meta_futureupdate_html($post, $box){
global $fu_key;
$value = get_post_meta($post->ID, $fu_key, true);
if(!$value) $value = ”;
echo ‘‘.”\n”
. ‘
. ‘
‘.”\n”;
}
function my_meta_futureupdate_update($post_id){
global $fu_key;
if(!wp_verify_nonce( $_POST[‘my_meta_futureupdate_nonce’], get_bloginfo(‘template_url’) . $fu_key)){
return $post_id;
}
if(defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE)
return $post_id;
if(‘page’ == $_POST[‘post_type’]){
if(!current_user_can(‘edit_page’, $post_id))
return $post_id;
}else{
if(!current_user_can(‘edit_post’, $post_id))
return $post_id;
}
if($parent_id = wp_is_post_revision($post_id)){
$old = get_post_meta($parent_id, $fu_key, true);
if($old)
update_metadata(‘post’, $post_id, $fu_key, $old);
}else{
if(isset($_POST[$fu_key]))
update_metadata(‘post’, $post_id, $fu_key, $_POST[$fu_key]);
}
}
add_action(‘admin_menu’, ‘my_meta_futureupdate_box’);
add_action(‘save_post’, ‘my_meta_futureupdate_update’);
?>
[/php]
と、苦労したところで「kzyz」さんがプラグインにしてくれていました(^_^;)
https://github.com/kzyz/future-update
コメント