jeudi 26 mars 2015

WordPress meta_query not working


I am having issues with a meta query on a custom post type.


The following arguments are set:



$args = array(
'post_type' => 'wp_comp_entries',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'wp_comp_entry_competition-id',
'value' => $_POST['competition-id'],
'compare' => '=',
),
array(
'key' => 'wp_comp_entry_email',
'value' => $_POST['email'],
'compare' => '=',
),
),
);


A print_r of this looks like:



Array
(
[post_type] => wp_comp_entries
[posts_per_page] => -1
[meta_query] => Array
(
[relation] => AND
[0] => Array
(
[key] => wp_comp_entry_competition-id
[value] => 972
[compare] => =
)

[1] => Array
(
[key] => wp_comp_entry_email
[value] => dan@tailored.im
[compare] => =
)

)

)


Which is great. I then run



$lookup = new WP_Query( $args );


The start of a print_r of $lookup looks like:



WP_Query Object
(
[query_vars] => Array
(
[post_type] => wp_comp_entries
[posts_per_page] => -1
[meta_query] => Array
(
)


As you can see the meta_query is empty. I have no idea what is causing this as at the bottom of that dump there is this:



[query] => Array
(
[post_type] => wp_comp_entries
[posts_per_page] => -1
[meta_query] => Array
(
[relation] => AND
[0] => Array
(
[key] => wp_comp_entry_competition-id
[value] => 972
[compare] => =
)

[1] => Array
(
[key] => wp_comp_entry_email
[value] => dan@tailored.im
[compare] => =
)

)

)


Which shows that my code is recognised, WP just isn't feeding it into it's query. I am lost and looking for any direction on why this could not be working?


-- EDIT --


I must add I have tried the standard query from the Codex with no joy either.





Aucun commentaire:

Enregistrer un commentaire