• Does anyone know of a way to automatically add a publish date to a post?

    A project I’m working on for a client has the following requirements;

    • Contributors will be adding posts within a specific category.
    • 1 post from that category will appear per day for one day on the homepage.
    • It’s a first-come, first-serve basis.

    The idea is, when a Contributor writes a post, we query the database, find all posts within that category and their corresponding publish dates, and add 1 day to the highest date found.

    I have the rest of it figured out, I just can’t figure out how to auto-add the publish date short of manually editing it.

    Any help would be greatly appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think this is what you mean…

    <?php
    //get latest post for category and if post was made in prior 24 hours display it
    $one_day_old = 1 * 86400; //1 day * seconds per day
    $cat_to_show = 1; //put your category id here
    
    $args=array(
      'cat' => $cat_to_show,
      'showposts'=>1,
      'caller_get_posts'=>1
    );
    $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post();
          $post_age = date('U') - mysql2date('U', $my_query->post->post_date_gmt);
          if ($post_age < $one_day_old) {
          echo 'Post is less than 24 hours old'; ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          } //if ($post_age
          endwhile;
        } //if ($my_query)
      wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    Thread Starter darrinb

    (@dbmartin)

    Close, but the issue is, you may 10 contributors on one particular day write a post. Basically the client wants vendors to submit ads as a “Deal of the Day”. These ads will appear on a first-come, first-serve basis and will display on the home page for one day only.

    So for example, starting with the very first vendor:

    • Vendor 1 writes a post at 8:00 AM on 12/10/09. The post’s publish date would be 2009-12-11.
    • Vendor 2 writes a post at 8:05 AM on 12/10/09. That post’s publish date should advance to 2009-12-12.

    Basically I need a way to auto-increment the publish date by 1 day when a post is created. The current logic is to query the database, look for all posts in the “Deals” category, find the highest publish date of those posts, and add 1 day to that date before adding the new post to the database.

    The problem is, I can’t figure out a way to over-ride the timestamp function in the dashboard short of manually changing the date, which isn’t an option since these are Contributors and they don’t have the option of manually changing the timestamp. Not to mention the client wants it automated.

    Basically I need a way to auto-increment the publish date by 1 day when a post is created.

    If you don’t find a plugin to do that, consider posting a “New Job Request” [1] to have a professional work with you, or consider joining and soliciting professional assistance from the wp-pro mailing list [2].

    [1] http://jobs.wordpress.net/postajob.php or http://www.elance.com/php/search/main/eolsearch.php?matchType=profile#page=1&matchKeywords=wordpress&catFilter=100

    [2] http://lists.automattic.com/mailman/listinfo/wp-pro

    Thread Starter darrinb

    (@dbmartin)

    Thanks Michael!

    I can query the database and the get the highest post date of a post within a category, and I can add a day to it, now I’m just trying to figure out how to update the $_POST query vars before inserting the new post into the db. If worse comes to worse, I’ll just set it a custom meta field and use it that way.

    Thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Queue Post’ is closed to new replies.