• Hi there. I’m doing a custom query in one of my templates and there is a little problem. These are the custom args:

    array('posts_per_page' => 10, 'offset' => 0,
       'meta_query' => array(array('key' => 'score',
       'value' => 0, 'type' => 'NUMERIC',
       'compare' => '>')), 'order_by' => 'meta_value_num',
       'order' => 'DESC');

    this doesn’t work but if I use 'value' => 1, 'compare' => '>=' it does. It seems to me that the error is in wp-includes/meta.php, core function _parse_meta_query. The function check the arguments calling empty() but ‘0’ is considered empty in PHP and so my query isn’t parsed correctly.

    I think that it’s a bug, am I missing something?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think you’re missing a comma after the meta_query array:

    $args = array(
    	'posts_per_page' => 10,
    	'offset' => 0,
    	'meta_query' => array(
       		array(
       			'key' => 'score',
     			'value' => 0,,
     			type' => 'NUMERIC',
       			'compare' => '>')
       		),
       	'order_by' => 'meta_value_num',
    	'order' => 'DESC'
    );
    Thread Starter zaerl

    (@zaerl)

    Hi esmi, as you can see from my original post I’m not missing a comma. With “it doesn’t work” I don’t mean that a PHP error is spawn but instead that the query returns erroneous data and (in my opinion) this is due to the call of empty() in the core file.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error with custom query’ is closed to new replies.