• Hi,

    I have the following code in my archive page and I was wondering how I can make it so it shows posts only after today’s date?

    <?php query_posts($query_string . '&orderby=date&order=ASC&posts_per_page=72'); ?>

    In other files, I use the following code to achieve it, but I can’t seem to work out how to implement the same in the structure above.

    'date_query' => array( 'after' => "today" )

    Thank you

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi amurado,
    Please try the following code:

    <?php
     query_posts(
      array(
       'post_type' => 'post',
       'orderby' => 'meta_value_num',
       'order' => 'DESC',
       'meta_query' => array(
        array(
         'value'         => date('Ymd', strtotime("today")),
         'compare'       => '>=',
         'type'          => 'DATE'
        )
       )
      )
     );
    ?>

    Hope this will help you.

    Hi,

    Have you looked at this post below? It has a similar question answered:

    https://www.ads-software.com/support/topic/show-events-with-start-dates-after-today-custom-post-type?replies=3

    Thread Starter amurado

    (@amurado)

    @cedcommerce Tried that and changed the post type to “movies” and it didn’t work. It now doesn’t show any posts on the front.

    @tsure Just took a look at that thread and it seems pretty similar to the above code and it didn’t work.

    Not sure what I’m doing wrong.

    I am re-reading your question again and it says “I have the following code in my archive page and I was wondering how I can make it so it shows posts only after today’s date?”

    I am thinking, wait, *after* today’s date? future posts are not published!

    Am I not understanding this correctly?

    Thread Starter amurado

    (@amurado)

    @tsure: Yes, that’s correct. I’ve set it so scheduled posts show up on the front end. This is a custom post type for “movies” to use as a movie database. So future movies will need to be shown.

    As you’re saying that I need a post that will be published in future but you want to need it now.
    The code I’ve provided earlier output blank because you don’t have a post right now published with that date. If you want to show all the future
    movies, you can publish a post of upcoming movies and assign them a category and can fetch those posts by that category.

    Thread Starter amurado

    (@amurado)

    @cedcommerce Is there no way to fetch all posts AFTER today with your code? Using something like the below:

    'date_query' => array( 'after' => "today" )

    Thank you

    Yeah it’s possible to fetch all the posts after today, but make sure that you have published those posts for future date.
    try the following code:

    <?php
    query_posts(
     array(
      'post_type'       => 'movies',
      'post_status'     => 'future',
     )
    );
    ?>

    Use the above query posts with the given parameter and fetch the posts.
    You’ll get all the posts, published for after today.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘query_posts and date_query?’ is closed to new replies.