You could check against the age of the post, and if the age of the post is older, don’t display the post.
I’ll write up something small for you.
[mod: please remember to use the pastebin for codes longer than 10 lines]
<?
/* Credited to KreativJustin */
$post_date = the_date('Ymd','','',FALSE);
// We gathered original date from the post, let's strip it down so we can use it
$post_year = substr($post_date,0,4); // Years stripped. 0 from left, 4 chars max
$post_month = substr($post_date,4,2); // Months stripped. 5 from left, 2 chars max
$post_day = substr($post_date,6,2); // Months stripped. 7 from left, 2 chars max
// Now we need to gather info for the current date.
$current_date = date('Ymd');
// Great, let's strip down the current date. We can just copy, paste, modify the top one!
$current_year = substr($current_date,0,4); // Years stripped. 0 from left, 4 chars max
$current_month = substr($current_date,4,2); // Months stripped. 5 from left, 2 chars max
$current_day = substr($current_date,6,2); // Months stripped. 7 from left, 2 chars max
// Let's turn them into usable strings
$post_usage = $post_year . $post_month . $post_day;
$current_usage = $current_year. $current_month . $current_day;
$difference = $current_usage-$post_usage;
if($difference > "3") { // Days
// Too old, do nothing
} else {
// Perfect age, display post here.
}
?>
This does work when inserted into a loop. I have used this code for other reasons within a post. Good luck!
Thanks man, I’ll give that at shot and see what kind of trouble I can get into.
Where should I put that?
No problem, if you have any questions or comments, please reply.
@kreativejustin
I have no clue how to use that, I’m barely literate when it comes to this stuff.
Looking at that code you provided – it’s comparing the post date to current date, then if it is 3 days old or less, it will display the posts.
How do I incorporate that into the code I have? Appreciate your help.
I believe this is resolved by adding a time parameter filter:
function filter_where($where = '') {
//posts in the last 3 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-3 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
(Hey Mod: Sorry about the code before)
Daily Digest – Page Template – Last 3 Days
My Page Template now displays the last 3 days of posts, listed under the date of posting. So cool, I love WP.
To improve this, I would like to have it display the last 3 days with posts. Problem: if I skip 3 days of posting, nothing would display.
If anyone has any comments about this implementation, improvements, etc. would welcome the input.
(I would also like to add Page Navigation to previous or next “day” – limited to only 1 day’s digest per page. That’s likely going to be a support request for another day.)
Well heck, I didn’t even know you could do that with wordpress. I learned something new today, thanks adkbasecamp