I have 3 posts that each have two meta values. The first meta value is one that they all share (ac_parent_event). The second is one that is unique to that post (ac_thischild_date). For this function, I am trying to query one post by both of the meta values. The query I have, as far as I know, should return the one post that has both values set to the values specified in the variables, but instead this returns the THREE posts that have the 'ac_parent_event' value, even though all three have different ac_thischild_date values. I've also tried using 'LIKE' instead of '=' with the same result. I've verified that $date and $parent_id are being passed successfully.

function ac_get_event_id_by_date($date, $parent_id) {
$matches = get_posts(array(
    'post_type' => 'tribe_events',
    'post_status' => array('draft', 'pending', 'publish'),
    'meta_query' => array(
        'key' => 'ac_thischild_date',
        'value' => $date,
        'compare' => '=',
        'key' => 'ac_parent_event',
        'value' => $parent_id,
        'compare' => '=',
    foreach ($matches as $post) {
        global $post;
        $chPost_id = get_the_ID();

    return $chPost_id;
  • 1
    for debugging purposes, it's easier to use WP_Query, then you can var_dump the query object and inspect the query vars and SQL request to see what's going on. – Milo Jan 17 '16 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.