如果页面处于“待定”状态,我将尝试显示最新的后期修订,默认情况下,如果页面处于待定状态,则显示404。但我希望它显示最新版本,直到页面更新。
下面的代码似乎只显示标题,我使用了一个钩子wp_insert_post_data
如果用户角色不是admin,则将帖子状态更改为“挂起”的函数。
该帖子在数据库中设置为挂起,但我无法获取以下代码来显示最新版本?
我也不知道如何防止它重定向到404页面?如果我登录,它将显示帖子,否则将显示404页。
<?php while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php
echo get_post_status(); //echo\'s pending
if(get_post_status() == \'pending\') {
$query = new WP_Query(array(\'post_type\' => \'revision\', \'post_parent\' => \'7\', \'posts_per_page\' => 1)); // 7 is the current page ID
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
the_content();
echo $post->ID;
}
}
wp_reset_postdata();
} else {
the_content();
}
?>
<?php endwhile; ?>
<?php endif; ?>
有什么建议吗?如果页面处于挂起状态,是否有更简单的方法显示修订?谢谢
Edit:
好的,我似乎使用以下代码工作:if(get_post_status() == \'pending\') {
$query = \'SELECT ID FROM `wp_posts` WHERE `post_parent` = \'.$post->ID.\' AND `post_type` = "revision" AND `post_status` = "pending" AND `post_title` <> "Auto Draft" AND TRIM(`post_content`) <> "" AND `post_name` NOT LIKE "%autosave%" ORDER BY `post_modified` DESC LIMIT 1\';
$revision_id = $wpdb->get_var($query);
$revision = wp_get_post_revision($revision_id);
$content = $revision->post_content;
$content = apply_filters(\'the_content\', $content);
$content = str_replace(\']]>\', \']]>\', $content);
echo $content;
wp_reset_postdata();
} else {
the_content();
}
所以现在的问题是-How can I prevent a page which is set as pending to redirecting to the 404 page?