Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type kalender, a template which displays all of the posts in this custom post type and a single-kalender.php. Everything works fine when the user is logged in but when logged out the single pages return a 404 error.

I'm assuming I get the 404 because I'm trying to display future posts when not logged in. How would I go ahead and solve this issue?

EDIT 1

$labels = array(
  'name' => __('Events'),
  'singular_name' => __('Event'),
  'add_new' => __('Nieuw event'),
  'add_new_item' => __('Nieuw event'),
  'edit_item' => __('Event bewerken'),
  'new_item' => __('Nieuw event'),
  'view_item' => __('Bekijk event'),
  'search_items' => __('Doorzoek Events'),
  'not_found' =>  __('Niets gevonden'),
  'not_found_in_trash' => __('Niets gevonden in de prullenbak'),
  'parent_item_colon' => ''
);

$args = array(
  'labels' => $labels,
  'public' => true,
  'query_var' => true,
  'menu_icon' => get_stylesheet_directory_uri() . '/img/events.png',
  'hierarchical' => false,
  'menu_position' => null,
  'rewrite' => array( 'with_front' => false ),
  'supports' => array('title','editor','thumbnail')
  ); 

register_post_type( 'kalender' , $args );
flush_rewrite_rules();

EDIT 2

I've added some code in the 404.php template which would detect if the page which is trying to load is in the custom post type kalender. This works:

<?php 
    global $wp_query;

    if ('kalender' == $wp_query->query_vars["post_type"]) {
        include 'single-kalender.php';
    }
    else{ ?>
        </div><!-- .menu-container -->
        <h1>Error 404</h1
<?php } ?>

Now I'm trying to query that specific single custom post type in the single-kalender.php template but I can't get it to work. The following query outputs no posts, even though the found_posts variable is 1 (works as expected) but the posts array remains empty unfortunately.

global $wp_query;
$name = $wp_query->query_vars["name"];

add_filter( 'posts_where', 'my_posts_where_from_today' );

$query = new WP_Query(array('post_status' => array( 'publish', 'future' ), 'post_type' => 'kalender', 'order' => 'ASC', 'name' => $name ));

When I use the generated query on my database it selects the single custom post type as expected, the generated query is the following:

SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.post_name = 'slug-of-the-post' AND wp_posts.post_type = 'kalender' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future') AND post_date > '2013-04-11'  ORDER BY wp_posts.post_date ASC 

If you want to check the whole print_r($query) see here: http://pastebin.com/cSzmXDVb

share|improve this question
    
Please post the code used to create your CPT. Chances are you have set incorrect capabilities on it. –  vancoder Apr 11 '13 at 16:36
    
No I didn't seriously called it CPT, it was just an example. I'll post the code above. –  user2019515 Apr 11 '13 at 16:38
    
Well default caps will be 'post', so as long as your anonymous users can read posts this should work. Do you have a caching plugin active? –  vancoder Apr 11 '13 at 16:44
    
No caching plugin active. I'm assuming anonymous users can't read the posts because they are scheduled to be posted in the future. –  user2019515 Apr 11 '13 at 16:54
1  
Okay I'm confused. Why do you want users to see posts that are not published until a future date? If you've built your CPT to use the publication date in a way other than the way it was intended, that was a mistake. You should create a custom field for your dates in your CPT, and leave the publication date alone. –  vancoder Apr 11 '13 at 16:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.