I have a post type gtre
and metadata price
.
The 'price' metadata I get using get_post_meta($post->ID, 'key', true)["price"];
So I don´t know how exactly should I write the args for WP_Query
constructor, so I can get the posts in order by the 'price
' meta data. I mean I want the query to ordered by 'price
'.
I have tried this:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$temp = $wp_query;
$wp_query = NULL;
$args = array('post_type' => 'gtre',
'posts_per_page'=>'6',
'order'=>'ASC',
'page'=>$paged,
'meta_query' => array(
'key' => 'price',
),
'orderby'=>'meta_value');
$wp_query = new WP_Query($args);
But I only get the posts in 'ASC
' order by time of posting.
How could be my '$args
' array so I can sort or order by the 'price
' meta data. And this 'price
' meta data I only get if I use 'get_post_meta($post->ID, 'key', true)["price"]
', I mean I can only get the price by using the function 'get_post_meta
'.
Any help? Thanks.