WordPress.org

Support

Support » How-To and Troubleshooting » Creating a list of posts based on today’s date in custom field

Creating a list of posts based on today’s date in custom field

  • charlieshack
    Member

    @charlieshack

    I want to create a list in the sidebar displaying the ‘filmtitle’ custom field of any posts which have today’s date (ddmmyyyy) as their custom field ‘releasedate’.

    Can anyone help me with this? Thanks so much in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • This worked in the sidebar.php when using the WordPress Default theme:

    <?php
       $args=array(
       'showposts'=>4,
       'meta_key'=>'releasedate',
       'meta_value'=>date('dmY'),
       'caller_get_posts'=>1
       );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
    $filmtitle = get_post_meta($my_query->post->ID, 'filmtitle', true);
    if ($filmtitle){
    echo 'Film Title: ' .$filmtitle;
    }
    endwhile;
    }
    ?>
    charlieshack
    Member

    @charlieshack

    Works perfectly! Thanks so much.

    Any idea how I could alter it to also show posts with a ‘releasedate’ of the previous 2 days or the following 4 days?

    It seems the way you have your date (19022009 dmY) in the custom field makes that near impossible with query_posts. If the releasedate was formatted like 20090219 (Ymd) for February 19, 2009, then you could do what you want–at least makes it possible with query_posts.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating a list of posts based on today’s date in custom field’ is closed to new replies.