Horje
Expired Posts Code to Exclude: Problem with 2011 Date - Wordpress Solution
[Solved] - Expired Posts Code to Exclude: Problem with 2011 Date - Wordpress Solution
Try following codes
I have code on my pages to exclude posts which have a particular deadline i have entered. The posts are archived and I enter the deadline as follows: 05/12/2010. I just tried to enter a deadline in 2011 with date 5/10/2011, and the post is not showing up so it seems to think it has expired. Maybe not recognizing the year? Any ideas why this might be happening? The code looks like this:
<?php while(have_posts()) : the_post(); ?>
<?php  //to check against expiration date;


$currentdate = date("mdY");
$expirationdate = get_post_custom_values('deadline');
if (is_null($expirationdate)) {
	$expirestring = '50503000'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP;
} else {
	
if (is_array($expirationdate)) {
	$expirestringarray = implode($expirationdate);
	}
$expirestring = str_replace("/","",$expirestringarray);
} //else

if (( $expirestring > $currentdate ) || (is_archive())) { ?>




Solution - 1

First, shouldn't your last line...

if (( $expirestring > $currentdate ) || (is_archive())) { ?>
be?
if (( $expirestring > $currentdate ) && (is_archive())) { ?>
Second, Try this for your date comparison:
$currentdate  = strtotime(date("m/d/Y"));
$expirationdate = strtotime(get_post_custom_values('deadline'));

if ($expirationdate > $currentdate && is_archive()) { ?>


Solution - 2

That's will help you..


<?php
if (have_posts()) :
     while (have_posts()) : the_post(); ?>
         $expirationtime = get_post_custom_values('expiration');
         if (is_array($expirationtime)) {
             $expirestring = implode($expirationtime);
         }

         $secondsbetween = strtotime($expirestring)-time();
         if ( $secondsbetween > 0 ) {
             // For exemple...
             the_title();
             the_excerpt();
         }
     endwhile;
endif;
?>


Solution - 3

Is the actual publish date of the post set to 2011 as well? If so, WP won't show the post.


Solution - 4

well the problem is how you are doing the comparison. If i follow your code correctly, at the end you have two strings, one is for today: 7062010 and the other one is for the expiration date: 5102011 and then you compare to see which one is grates. if (( $expirestring > $currentdate ) That is not a good way to do it. since, even though the year is bigger, the month isn't, so your expiration date is actually a smaller number. That is why you end up with your posts not showing up. A better way to do it is to work with dates directly or to firs compare the year, then the month and then the day. Now I see you are expecting an array as the value for your expiration date. What is the format of that array, and why an array?

Date: 2022-10-21 05:21:58
Category: Wordpress
More for You