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 created a custom post type "events" to display event information. All links to the events work well when I am logged in. However, if I am not log in, all the links for events that set in the future are broken - having a page not found message; but these pages will display as soon as I log in. -- all links for events in the past are working well no matter log in or not.

Please advice what cause the problem and how to fix it.

Thanks

I have the following code in the functions.php in my child theme:

function enable_event_posttype() {
    register_post_type( 'events',
        array(
            'labels' => array(
                'name' => __( 'Events' ),
                'singular_name' => __( 'Event' ),
                'add_new' => __( 'Add New Event' ),
                'add_new_item' => __( 'Add New Event' ),
                'edit_item' => __( 'Edit Event' ),
                'new_item' => __( 'Add New Event' ),
                'view_item' => __( 'View Event' ),
                'search_items' => __( 'Search Event' ),
                'not_found' => __( 'No events found' ),
                'not_found_in_trash' => __( 'No events found in trash' )
            ),
            'public' => true,
            'scheduled' => true,                 
            'supports' => array( 'title', 'editor', 'comments'),
            'capability_type' => 'post',
            'rewrite' => array("slug" => "events"), // Permalinks format
            'menu_icon' => get_bloginfo('stylesheet_directory') . '/images/date.png',  // Icon Path
            'menu_position' => '5'
        )
    );
}

add_action( 'init', 'enable_event_posttype' );
share|improve this question
1  
how are you storing event dates? post dates in the future are scheduled, not published, so aren't publicly visible until that date. the way to handle this is to store the event date as meta data rather than use the publish date. –  Milo Feb 26 '13 at 15:42
1  
Please post relevant code; otherwise, the question is impossible to answer. –  Chip Bennett Feb 26 '13 at 15:47
    
I have the following code in the function.php in my child theme: –  Lisha Feb 26 '13 at 15:59
    
sorry, the code is too long to be added here, so I have added it at the end of the question. –  Lisha Feb 26 '13 at 16:06
    
Hi Milo, thanks, and yes, I store the event dates in the post dates, and set the visibility to Public, and the status to Scheduled. Please advice in more detail how to handle it using meta data as I don't know much about it. –  Lisha Feb 26 '13 at 16:15
add comment

1 Answer

up vote 0 down vote accepted

I would recommend downloading the excellent Advanced Custom Fields plugin and using that. It will let you easily create a field to accept a date and it uses a date picker to ensure you are getting the proper format stored.

Then, in your code, all you have to do is this: echo get_field('event_date'); ... assuming you named your field event_date.

There is a lot more you can do with the plugin, but it would definitely help you in this case.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.