Search code examples
wordpresspermalinksposts

scheduled posts are showing when I am logged in


I have posts and they are upcoming, but they are visible in site. So when I am logged in admin panel, that post's single page is ok, but when I logged out in that case it redirects to error 404 page. What's the problem? How can I solve this?


Solution

  • Found a solution, just added this to my functions.php and future posts are showing in single.php:

    add_filter('the_posts', '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;
    }