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 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 ...
share|improve this question
    
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. –  user44082 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 –  user44082 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
show 1 more comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.