Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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