Order is breaking wp_query

Question

Have never encountered anything like this. Running a simple query of custom post types, show only those that the current user is the author, and sort them by a custom meta field.

global $current_user;
$user = wp_get_current_user();

$args = array(
    'post_type'              => 'order',
    'post_status'            => 'publish',
    'author'                 => $current_user->ID,   
    'posts_per_page'         => '-1',
    'meta_query'             => array(
                                    array(
                                        'key' => 'completed',
                                        'value' => ''
                                    )
                                ),
   

);


$query = new WP_Query( $args );

This returns results. When I add in

'order'          => 'ASC',

The Query returns no results. Makes absolutely no sense to me.

Just for reference, here is the entire section.

// ========== ORDERS QUERY CODE ==========

$orders = '';

global $current_user;
$user = wp_get_current_user();

$args = array(
    'post_type'              => 'order',
    'post_status'            => 'publish',
    'author'                 => $current_user->ID,   
    'posts_per_page'         => '-1',
    'meta_query'             => array(
                                    array(
                                        'key' => 'completed',
                                        'value' => ''
                                    )
                                ),
    'order'                  => 'ASC',
   

);


$query = new WP_Query( $args );



if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();

        $thePostID = get_the_ID();
        $shortDesc = wordwrap(substr(get_the_content(), 0, 100), 99, '...');
        $quantity = get_post_meta( $thePostID, 'order_quantity', true );
        
        $orders .= '<div class="order-single order-'.$thePostID.'">
                        <div class="row">
                            <div class="col-4">
                                <div class="single-cal">
                                    <div class="month">'.date_i18n('F', strtotime(get_post_meta( $thePostID, 'delivery_date', true ))).'</div>
                                    <div class="day">'.date_i18n('j', strtotime(get_post_meta( $thePostID, 'delivery_date', true ))).'</div>
                                </div>
                            </div>
                            <div class="col-8">
                                <a class="order-customer"  href="'.get_the_permalink().'">
                                    '.get_the_title().'
                                </a>
                                <div class="order-desc">
                                    <div class="qty"><strong>Quantity:</strong> '.$quantity.'</div>
                                    '.$shortDesc.'
                                </div>
                            </div>
                        </div>
                    </div>';
        
    }
} else {
    $orders .= 'No Orders Found.  <a href="/add">Click Here</a> to enter your first Order!';
}

wp_reset_postdata();
0
DigitalCardinal 2 months 0 Answers 16 views 0

Leave an answer