Search code examples
phpwordpressposts

WordPress don't show older posts


Trying to not show older posts in a query_posts() function but it doesn't appear to be working. I need to not show posts past the current date and only show ones yet to happen. I'm using the publish date to set the values in the admin side but I get get the query to work.

current code is:

<?php $args = array( 
                                        'order_by'      => 'date', 
                                        'order'         => 'ASC', 
                                        'year'          => date('Y'),                         
                                        'monthnum'      => date('m'),                       
                                        'day'           => date('d') 
                                        ); ?>
                    <?php query_posts( $args ); ?>

Solution

  • It's covered, right in the Codex. Example:

    $today = getdate();
    $args = array(
        'post_status' => 'pending',
        'date_query' => array(
            'after' => array(
                'year'  => $today['year'],
                'month' => $today['mon'],
                'day'   => $today['mday'],
            ),
        ),
    );
    $query = new WP_Query( $args );