0

I am trying to get all posts to be displayed on a certain date.

For example today Tuesday I want all posts to be displayed. It doesn't matter that the posts were created today (Tuesday) or last week or last year - I just want a loop that will display all post of the current day.

Tomorrow (Wednesday) I want all post to be displayed.

I have created this code but it isn't working for me and I am getting a little frustrated.

Here is my code.

<?php
$day = date('j');
query_posts( 'day='.$current_day);
query_posts('cat=9&posts_per_page=2' );

if (have_posts()) :
    while (have_posts()) :
        the_post(); ?> 
        <div id="eventTitle">
            <span class="thetimeevent">
                <?php the_field('time'); ?>
            </span>
            <a href="<?php the_permalink() ?>" class="eventFeed">
                <?php the_title(); ?>
            </a>
        </div>
        <?php
    endwhile;
endif;
wp_reset_query();
?>

Thank you for any help in advance :)

6
  • Please don't use query_posts. I'm almost certain I once told you this before. Might be wrong though. Use WP_Query. BTW, you cannot use two instances of query_posts the way you did. Commented May 27, 2014 at 10:30
  • Hey Pieter, I did use WP Query before but after many good searches I kept finding query_post. I am with you that using wp_query is much better. I cannot for the life of me figure this out! Thanks again.
    – Tired_Man
    Commented May 27, 2014 at 10:33
  • On which page/template are you using your code Commented May 27, 2014 at 10:35
  • I am creating a custom theme and it is on a custom homepage.
    – Tired_Man
    Commented May 27, 2014 at 10:36
  • Have a look at this post Commented May 27, 2014 at 14:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.