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 need to showing message in post , but after one month from publish date.

I try to make it before ask you, but I can't

this is my code

                $publish_date =  $post->post_date_gmt;
        $today = date('d-m-Y h:i:s');
        $nextMonth = mktime(0 , $publish_date('m')+1 , 0 , 0 , 0,0);
        echo 'Publish Date:'.$publish_date.'<br/>';
        echo 'Today Date:'.$today.'<br/>';
        echo 'Next Month:'.$nextMonth;
        if($today => $nextMonth){
            echo 'One Month or more for publish post';
        } else {
            echo '';
        }
share|improve this question

2 Answers 2

up vote 1 down vote accepted

Custom conditional I wrote for my theme (mostly to kick some widgets and ads from newer posts), works nicely:

function is_old_post( $days = 14 ) {

    if( !is_single() )
       return false;

    $id = get_the_ID();
    $date = get_post_field( 'post_date', $id );

    if( strtotime( $date ) < strtotime( "-{$days} days" ) )
        return true;

   return false;
}
share|improve this answer
    
oh great , Thanks Rarst –  AboSami Feb 17 '11 at 20:54

Couple of things:

  1. Your today date should have the format 'Y-m-d h:i:s'.
  2. You might want to use current_time('mysql') instead, anyways (WP core function).
  3. $publish_date('m')?, and mktime creates a unix timestamp, afaik, not a mysql one, which is what you're after, so instead of those, try this:

    $ts = strtotime($today);
    $m = date('m', $ts);
    $Y = date('Y', $ts);
    if ($m < 12) { $m++; } else { $m = 1; $Y++; }
    $nextMonth = date('Y-m-d', mktime( 0, 0, 0, $m, date('d', $ts), $Y ));
    
share|improve this answer
    
thanks , I'm using now , it is very great. –  AboSami Feb 17 '11 at 20:53

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.