• So this is my problem. When I sort the posts with a meta_key price I get 442 posts as a result but once I comment ‘meta_key’ => ‘price’ I get 549 results. The others don’t show up because they don’t have the custom field price.

    $args = array(
    'posts_per_page' => -1,
    'post_status' => 'publish',
    'post_type' => 'medicament',
    'orderby' => 'meta_value_num',
    'meta_key' => 'price',
    'order' => 'ASC',
    'meta_query' => array(
            array(
                'key' => 'client',
                'value' => 239,
                'compare' => '=',
                'type' => 'NUMERIC'
            ),
    ),
    );
    
    $the_query = new WP_QUERY( $args );

    Do you know a way to not exclude posts that do not have the custom field price and keep the sorting by price?

    Thank you

The topic ‘meta_value_num orderby expells posts with null custom field’ is closed to new replies.