Get Venue by Meta Query returning empty array

WordPress Event Management, Calendars & Registration Forums Report A Bug Get Venue by Meta Query returning empty array

This topic contains 3 replies, has 3 voices, and was last updated by  Stephen Harris 2 weeks, 4 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #43827

    Currently trying to check and see if a venue coming from an API exists in EO based on its address/city/state. For testing purposes, I have removed the API calls and am just testing with hardcoded strings that are known to be in the database:

    $venue_query = array(
            'key' => '_state',
            'value' => 'NY'
    $args = array(
        'meta_query' => $venue_query,
    $o .= var_export($args, true);
    $eoVenues = eo_get_venues($args);
    $o .= var_export($eoVenues, true);
    return $o;

    This code is run as part of a shortcode, and the output is:

    array ( 'meta_query' => array ( 0 => array ( 'key' => '_state', 'value' => 'NY', ), ), )
    array ( )

    The first line of the output shows the query variables being passed into eo_get_venues(), and the second line shows that eo_get_venues() is returning an empty array. I have two venues that appear in the admin list which have states of NY, and two entries in the wp_eo_venuemeta table where key equals _city and value equals NY. When I remove the meta query, all venues are returned as expected.

    WordPress version 6.5.2

    Event Organiser version 3.12.5

    PHP version 8.1

    Let me know if there’s any other information I can provide that would be useful to help debug this

    Beth Moeller

    Digging into this a bit more, the Debug Bar plugin is showing the following query being executed:

    SELECT DISTINCT t.term_id
    FROM wp_terms AS t INNER JOIN wp_termmeta ON ( t.term_id = wp_termmeta.term_id ) INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
    WHERE tt.taxonomy IN ('event-venue') AND (
        ( wp_termmeta.meta_key = '_state' AND wp_termmeta.meta_value = 'NY' )

    This query was generated by WP_Term_Query->get_terms(), which through a few other functions was called by eo_get_venues(). It appears the issue is that the query is checking in wp_termmeta for the venue meta info, and not the wp_eo_venuemeta table.

    Beth Moeller

    Hi there,

    I would be interested in a solution for this. I guess this is the reason why seeing events by venue currently doesn’t list the events on the venue pages.

    Philippe Zuber


    Apologies for the not responding to this sooner. The plug-in does use (indirectly) WP_Term_Query which will ordinarily use the wp-terms table. However, the plug-in uses the following code to “move” the meta-data query in the request:

    function _eventorganiser_venue_meta_query_fix( $wp_term_query ) {
        $args = $wp_term_query->query_vars;
        if ( !empty($args['taxonomy']) && in_array( 'event-venue', $args['taxonomy'] ) && ! empty( $args['meta_query'] ) ) {
            $args['cache_domain'] .= 'eo_get_venues:'.  md5( serialize( $args['meta_query'] ) );
            $args['eo_venue_meta_query'] = $args['meta_query'];
            unset( $args['meta_query'] );
            $wp_term_query->query_vars = $args;
    add_action( 'parse_term_query', '_eventorganiser_venue_meta_query_fix' );

    As you can see it will only do this if:

    • The taxonomy is set
      • The taxonomy contains ‘event-venue’
      • The meta query is set

    That should be the cause when using eo_get_venues() with a meta query, however I suppose there may be another plug-in that is either removing that filter or otherwise changing the values being filtered so that conditional fails.

    Stephen Harris
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.