0

There is something missing because this is driving me crazy at the moment.

I'm using the wp_query with the following args.

$args = array(
    'post_type'     => 'project',
    'post_status'   => 'publish',
    'meta_query'    => array(
        array(
            'key'       => '_sf_project_budget',
            'value'     => '6',
            //'compare'     => '=',
            //'type'        => 'NUMERIC'
        )
    )       
);
$search_query = new WP_Query($args); 

When print_r the $search_query I can see the following:

WP_Query Object
(
    [query_vars] => Array
        (
            [post_type] => project
            [post_status] => publish
            [meta_query] => Array
                (
                    [0] => Array
                        (
                            [key] => _sf_project_budget
                            [value] => 6
                        )

                ) 

But the "SQL" doesn't seem to change:

[request] =>  SELECT SQL_CALC_FOUND_ROWS  wps_posts.* FROM wps_posts  
WHERE 1=1  AND wps_posts.post_type = 'project' 
AND (wps_posts.post_status = 'publish')  
ORDER BY wps_posts.post_date DESC LIMIT 0, 10

Shouldn't this change to incorporate the meta query vars?

Can't see what I'm doing wrong or what's missing, tried different things and it brings all the posts all the time. I checked in postmeta table and I can see that the values are there.

Any pointers in the right direction?

Thank you.

5
  • why is the 'compare' line commented out? there needs to be a comparison for the meta_query to have any effect
    – anu
    Commented May 27, 2011 at 10:44
  • @spartacus comment or not comment still produces de same result. Also the default value is '='.
    – Yeope
    Commented May 27, 2011 at 10:48
  • 1
    The meta query is converted by _get_meta_sql. You can check the output by hooking into get_meta_sql. Dump that value and see what it gives.
    – Jan Fabry
    Commented May 27, 2011 at 11:49
  • @Jan Fabry, spot on. My problem was coding against the wrong version of wordpress were the meta_query wasn't supported. Update wordpress to the latest version and it worked fine. Totaly my mistake.
    – Yeope
    Commented May 27, 2011 at 13:50
  • Ah, this can happen to anybody, especially when you work on multiple projects at the same time. I duplicated my comment as an answer so you can accept it and mark this question as answered.
    – Jan Fabry
    Commented May 27, 2011 at 13:55

1 Answer 1

1

The meta query is converted by _get_meta_sql(). You can check the output by hooking into get_meta_sql. Dump that value and see what it gives.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.