0

as the title indicates I am trying to make a query for the post closest to today's date. I know this is a duplicate post but the ones I have found on the topic has not been able to solve my problem.

my code:

$args = array( 'type'=>'post', 'orderby'=>'name',
           'order'=>'ASC', 'taxonomy'=>'category' );
$categories = get_categories( $args );

foreach ( $categories as $cat ) {
$args = array( 'post_type'      => 'event',
               'numberposts'    => 1,
               'cat'            => $cat->cat_ID,
               'meta_key'       => '_date',
               'order'          => 'DESC',
               'order_by'       => 'meta_value',
               'no_found_rows'  => true,
               'meta_query'     => array(array(
                   'key'    => '_date',
                   'value'  => date('Ymd'),
                   'compare'=> '>=',
                   'type'   => 'NUMERIC'
               ))
              );
$query = new WP_Query( $args );

I have been looking to this post for help: Arrange Posts By Date In Order Of Closest To The Current Date

What works: The query does not return post's with a date that has passed.

What does not: The query will not order by the meta key '_date', I always end up with the most/least recently created post rather than what I am trying to achieve.

Any help is appreciated, thank you.

1 Answer 1

0

The parameter should be orderby rather than order_by. (See codex)

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.