WordPress: Display posts by custom select query

I need Wp_query with two custom fields, one custom field for orderby and another: (if this key exists in the post so show the post else dont add this post to query.) I tried like this but doesnt work… Any help?

$args = array(
'post_type' => 'post',
'meta_query' => array(
    array(
        'key' => 'Apple',
    ),
    array(
        'key' => 'Price',
        'type' => 'numeric',
    )
),
'orderby' => 'meta_value_num',
'paged' => get_query_var('paged'),
'order'=> 'DESC',
    );
$the_query = new WP_Query( $args );

As you can see I want to show posts which has custom field “Apple”, and want to order by the custom field “Price”, From lowest to highest price.

Related posts

Leave a Reply

1 comment

  1. try this:

    $args = array(
    'post_type' => 'post',
    'meta_query' => array(
        array(
            'key' => 'Apple',
            'value' => '',
            'compare' => 'NOT LIKE'
        )
    ),
    'meta_key' => 'Price',
    'orderby' => 'meta_value_num',
    'paged' => get_query_var('paged'),
    'order'=> 'DESC',
        );
    $the_query = new WP_Query( $args );