Removing Expired Posts from Page of Posts, but Keep Them Available
I am trying to find a good way to remove posts from a page of posts at a specified expiration date/time, but keep them available at the same URL, so I don’t end up with 404 errors for every event ever created. An easy way would be to use the Post Expirator plugin to expire them to a different category, except that changing the category changes the permalink, so I’d have to add a new redirect to my htaccess file for every single event when it expires (which seems like a poor long term solution).
I am using the Twenty Eleven theme with various plugins. I have created several pages that use custom templates I created to display summarized content from all posts of a specific category. For example, I have an events page that displays a list of all posts of the category “events.” On this page of (event) posts, basic information is listed for each event (I used the Types plugin for this–super handy), and the title is linked to the actual post with further details.
When an event is over with, I don’t want it to display on this page of posts anymore. I do, however, still want it to be available at the same URL. Basically I need a way to check in the args for query_posts() if the post has been “expired” that doesn’t result in any other changes to the post (URL, change to draft, etc.). Any suggestions?
Here is how my page of (event) posts works:
1. Set the query
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args= array( 'category_name' => 'events', 'post_status' => 'publish', 'paged' => $paged, 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'ASC' ); query_posts($args); ?>
2. The loop:
<?php if( have_posts() ) : twentyeleven_content_nav( 'nav-above' ); while ( have_posts() ) : the_post(); get_template_part( 'content', 'events' ); endwhile; twentyeleven_content_nav( 'nav-below' ); else : // Display a message and search form for if there are no events ?>
- The topic ‘Removing Expired Posts from Page of Posts, but Keep Them Available’ is closed to new replies.