1

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.

2

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 );
  • Thank you so much!!! it works I was trying with select query, but this is much easier. – andys Jan 10 '12 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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