WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] If The Post has been published within a week (4 posts)

  1. Tom
    Member
    Posted 4 years ago #

    I thought I was becoming a guru of wordpress, but I was stumped today.

    I would like an if statement that checks if the post has been published for more than a week. If it hasn't, I'll display a "New" sticker. If it has, then the sticker goes away.

    Seems simple enough, but after an hour of searching and attempting, I figured I would just ask.

  2. MichaelH
    Member
    Posted 4 years ago #

    <?php
    $mylimit=7 * 86400; //days * seconds per day
    //$post_age = date('U') - get_post_time('U');
    $post_age = date('U') - mysql2date('U', $post->post_date_gmt);
    if ($post_age < $mylimit) {
    echo 'this post is within my date limit ';
    }
    ?>
  3. Tom
    Member
    Posted 4 years ago #

    I bow to the master bow

    Question though: Why multiply by the seconds per day?

    As I typed that, I realized why. The MySQL speaks in seconds, so how many seconds in a week? Well you'd multiply the number of seconds in a day times the number of days. So if the post is a week old, it echos.

    Never mind, question answered. Still bowing. Any advice for a kid trying to break out from the pack around here?

  4. MichaelH
    Member
    Posted 4 years ago #

    Any advice for a kid trying to break out from the pack around here?

    Buy low and sell high!!

Topic Closed

This topic has been closed to new replies.

About this Topic