0

I thought that this already works but now I tested it and it seems that it no longer works.
I have this code:

wp_reset_query();
$args=array(
    'posts_per_page' => 3,
    'meta_key' => 'info_tab_1',
    'orderby' => 'meta_value_num',
    'order' => 'DESC'           
);
$info_tab = null;
$info_tab=new WP_Query( $args );

print_r($args); prints:

Array ( 
  [posts_per_page] => 3 
  [meta_key] => info_tab_1 
  [orderby] => meta_value_num 
  [order] => DESC 
)

print_r($info_tab); prints:

WP_Query Object ( 
  [query_vars] => Array ( 
    [posts_per_page] => 3 
    [meta_key] => info_tab_1 
    [orderby] => title 
    [order] => ASC 
    [error] => 
    [m] => 
    [p] => 0 ...
  • you need to change 'orderby' => 'meta_value_num', to 'orderby' => 'meta_value', - orderby only accepts certain parameters – Howdy_McGee Dec 18 '13 at 20:50
  • @Howdy_McGee no difference. And in meta value info_tab_1 I have int values. – okonik Dec 18 '13 at 21:04
  • Cannot reproduce, I get meta_value_num correctly preserved in WP_Query using your snippet. Check for offending filters, etc. – Rarst Dec 18 '13 at 21:31
  • @Rarst What kind of filters? WP_Query for this block on this page every time returns order by title and order ASC. I meen that rand, date and etc orderby doesn't works. The same is about DESC/ASC order.. it returns every time ASC – okonik Dec 18 '13 at 21:41
  • Unfortunately there is ton of hooks in WP_Query where things can mess it up. You can use something like Query Monitor to look into it. – Rarst Dec 18 '13 at 21:43

Your Answer

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

Browse other questions tagged or ask your own question.