1

我在 Wordpress 上有一个系统,其中事件是预定的帖子和循环中的单词。

但是我只是注意到,当单击一个事件并转到它的页面时,它会给出 404。我可以在登录时预览它,但是,即使它当前已安排,我也需要它对任何人可见。

有没有办法更改权限,以便任何人都可以查看特定的预定帖子类型?

谢谢!

4

3 回答 3

3

编辑:

尝试将此函数添加到您的 functions.php 文件中:

/* Show future posts */
function show_future_posts($posts)
{
   global $wp_query, $wpdb;
   if(is_single() && $wp_query->post_count == 0)
   {
      $posts = $wpdb->get_results($wp_query->request);
   }
   return $posts;
}
add_filter('the_posts', 'show_future_posts');
于 2012-09-24T23:42:38.137 回答
1

未来的帖子有点像 Catch-22:您可以在任何好的老式 Wordpress 循环中查询它们,但直接导航到它们是不可能的......至少在标准的 Wordpress 范围内:

<?php
$q = new WP_Query(array('post_status'=>'future'));
if($q->have_posts()) : while($q->have_posts()) : $q->the_post;
    echo '<a href="'.get_permalink().'">'.get_the_title().'</a>'; //404 when clicked
endwhile;endif;
?>

这样做的原因不是因为权限。这是因为这就是它在 Wordpress 核心中的构建方式。未来的帖子在特定日期之前不会被查看。试图让未来的帖子可供查看是对“未来”状态的滥用,并且违背了其整个目的,即安排帖子或页面在到达指定日期时自动切换到“已发布”状态。

但是,如果您仍然想让 Future Posts 像普通帖子一样可用,那么这个讨论可能会阐明各种方法和插件,以使一切按照您想要的方式发生。

祝你好运。

于 2012-09-25T03:09:50.113 回答
0

I tried several plugins and suggestions for this problem, but none worked to show a single custom post type template page to non-logged in users. Eventually I found my answer:

https://wordpress.stackexchange.com/questions/44202/how-to-set-a-custom-post-type-to-have-viewable-future-posts/70155#70155

于 2012-10-23T07:41:18.070 回答