The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. charlieshack
    Posted 7 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
    Posted 7 years ago #

    This worked in the sidebar.php when using the WordPress Default theme:

    $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>
    $filmtitle = get_post_meta($my_query->post->ID, 'filmtitle', true);
    if ($filmtitle){
    echo 'Film Title: ' .$filmtitle;
  3. charlieshack
    Posted 7 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
    Posted 7 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