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] => [email protected]
[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] => [email protected]
[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.
print_r
output of$lookup
the WP_Query object, look for therequest
property and post it here. That's the MySQL statement itself, it should tell us more.[request] => SELECT sosen_posts.* FROM sosen_posts WHERE 1=1 AND sosen_posts.post_type = 'wp_comp_entries' AND (sosen_posts.post_status = 'publish' OR sosen_posts.post_status = 'future' OR sosen_posts.post_status = 'draft' OR sosen_posts.post_status = 'pending' OR sosen_posts.post_status = 'private') ORDER BY sosen_posts.post_date DESC
meta_key =
etc then it works but I need to filter on two meta keys.wp_comp_entry_competition-id
? Try it without that part.