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.

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.