Order by meta_key not working
-
Helo,
I have multiple meta_key value pairs inside my custom posts. So to work around this what I did is that I ran a WP_QUERY initially which creates an array of posts ID which I then pass to load more to load those.The array that I build using WP_Query is in the correct order. However when I use the IDs in post_in parameter it is not displaying them in the given order. I have also tried to give orderby=”meta_value_num” parameter but it doesnt work either.
Here is WP_QUERY which is working perfectly
`$loop = new WP_Query(
array(
‘post_type’ => ‘properties’,
‘posts_per_page’ => -1,
‘meta_query’ => array(
array(
‘key’ => ‘listing_type’,
‘value’ => array(3,2),
‘type’ => ‘NUMERIC’,
),
array(
‘key’ => ‘payment_status’,
‘value’ => ‘yes’,),
array(
‘key’ => ‘expired’,
‘value’ => ‘no’,),
),
‘orderby’ => ‘meta_value_num’,
‘meta_key’ => ‘listing_type’,
‘order’ => ‘DESC’
));Here is the shortcode:
[ajax_load_more post_type=”properties” post__in=”‘.implode(‘,’,$featured).'” posts_per_page=”10″ scroll=”false” transition=”fade” button_label=”‘.$l_more.'” button_loading_label=”‘.$l_more_2.'” container_type=”ul” css_classes=”items”,orderby=”meta_value_num” meta_key=”listing_type”]However it doesnt order posts as it should because $featured array has it in required order. Even if I remove order by and meta_key parameter it doesnt work.
Please Help
Ahmar
- The topic ‘Order by meta_key not working’ is closed to new replies.