I’ve setup a CPT to act the same ways as posts but used to post event details.
Thing is that some of the posts are in the future and such have a future date set on them. Problem is that normal users cannot see these posts.
So:
- How do I alter archive-events.php to list future posts too? Showing far future posts first and oldest posts last while maintaining pagination.
- How do I make it so that when a user clicks a future post they don’t get a 404 page not found as the post is not technically published yet?
I’ve been able to solve this myself. My entire code for registering the CPT:
So to allow posts to be visable to all users even if they are set in the future you need to do the following:
We remove the action that deals with posting later and apply our own action to force it to be published despite it having a future date with:
Then all we now need to do is show future posts on the archive page by filtering
posts_where
:Brady, I can’t thank you enough for leading me to this solution. My client had already set all of the event dates without a custom field, and I wasn’t about to go back and change everything. Your code initially threw an error when trying to post, but it worked with the following slight modifications (made to match the format used in wp-includes/post.php):
and
I spent awhile trying to figure this out. Hope it helps someone else!
Without change the post status you can display future posts single and archive with pre_get_posts too: