WordPress.org

Ready to get started?Download WordPress

Forums

Creating a list of posts based on today's date in custom field (4 posts)

  1. charlieshack
    Member
    Posted 5 years ago #

    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.

  2. MichaelH
    Member
    Posted 5 years ago #

    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;
    }
    ?>
  3. charlieshack
    Member
    Posted 5 years ago #

    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?

  4. MichaelH
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic