-1

I am trying to do a meta_query, but not getting expected results. In this particular case, the key in question is "_EventHideFromUpcoming" (see below) with a value of "yes" (stored as a string). Also, if the value is not "yes", the key "_EventHideFromUpcoming" is not present at all.

I have the following query:

date_default_timezone_set('America/New_York');
$now = date('Y-m-d H:i:s');
$args = array(
    'post_type' => 'tribe_events',
    'posts_per_page' => '-1',
    'orderby' => '_EventStartDate',
    'order' => 'ASC',
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key' => '_EventEndDate',
            'value' => $now,
            'compare' => '>=',
        ),
        array(
        'relation' => 'OR',
            array(
                'key' => '_EventHideFromUpcoming',
                'compare' => 'NOT EXISTS',
            ),
            array(
                'key' => '_EventHideFromUpcoming',
                'value' => 'yes',
                'compare' => '=',
            ),
        ),
    ),
);

I've tried reducing my query down to simply getting one result with "_EventHideFromUpcoming" set to "yes" but still not able to. I've tried using essentially the same query with different meta keys and it works. It seems like all "_EventHideFromUpcoming" set to "yes" are being filtered out before I run my query.

  • Down voted since questions about integration with plugins/themes just can not be answered without knowing the fine details of how those plugins work. Preferably questions should be about your code in a "vanilla" enviroment. – Mark Kaplun Oct 16 '17 at 5:19
  • Ok. Thanks. I edited my question to remove the part specific about the plugin. – egauvin Oct 16 '17 at 11:00
3

It is not working because there is a custom query in the events plugin that adds the posts to be ignored (not returned) when you run WP_Query. See getHideFromUpcomingEvents() method in the-events-calendar/src/Tribe/Query.php. But there is however a filter hook that you can use there to do whatever. See the following sample code:

function wpse283031_hide_ids( $ids )
{
    $ids = [];
    return $ids;
}
/* this filter should be added **before** you run WP_Query */
add_filter( 'tribe_events_hide_from_upcoming_ids', 'wpse283031_hide_ids' );

Another thing you can try is add 'suppress_filters' => true to your query args. As in:

$args = [
    ...
    'suppress_filters' => true
];
  • +1 for suppres_filters.... although this obviously might be too much suppression ;) – Mark Kaplun Oct 16 '17 at 5:21
  • Do you mean the wpse283031_hide_ids function? If so, the $ids contains the post IDs that will not be returned in the results. – Paul G Oct 17 '17 at 1:56
  • When I looked at the function in, the-events-calendar/src/Tribe/Query.php, I thought it looked like the function wpse283031_hide_ids you provided shown above applied to the filter tribe_events_hide_from_upcoming_ids was actually removing all the id's from the id's that would be hidden. I kept $ids = []; and it looks like it's keeping all the events flagged as _EventHideFromUpcoming. – egauvin Oct 19 '17 at 0:29

Your Answer

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

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