Event-Venue Queries

Querying Venues

In Event Organiser Pro you can query venues matching certain meta data (see venue custom fields). This is identical in form to the normal post ‘meta_query’ you can use with WP_Query.

Parameters

To retrieve venues matching certain custom fields criteria you can use the eo_get_venues() function with the ‘meta_query’ argument:

 $venues = eo_get_venues( array( 'meta_query' => $venue_query ) );

where $venue_query is a 2-dimensional array, e.g. to get all venues in Edinburgh:

 $venue_query = array(
    array(
       'key' => '_city',
       'value' => 'Edinburgh',
    )
 );
 $edinburgh_venues = eo_get_venues( array( 'meta_query' => $venue_query ) );

Each inner-array can contain the following

  • key (string) – Venue custom field key.
  • value (string|array) – Venue custom field value (Note: Array support is limited to a compare value of ‘IN’, ‘NOT IN’, ‘BETWEEN’, or ‘NOT BETWEEN’)
  • compare – how the query should match the key-value. Possible values are ‘=’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘<=’, ‘LIKE’, ‘NOT LIKE’, ‘IN’, ‘NOT IN’, ‘BETWEEN’, ‘NOT BETWEEN’. Default value is ‘=’.
  • type (string) – The custom field type. Possible values are ‘NUMERIC’, ‘BINARY’, ‘CHAR’, ‘DATE’, ‘DATETIME’, ‘DECIMAL’, ‘SIGNED’, ‘TIME’, ‘UNSIGNED’. Default value is ‘CHAR’.

Examples

For instance to get venues which are not in Scotland:

 $venue_query = array(
    array(
       'key' => '_country',
       'value' => 'Scotland',
       'compare' => '!='
    )
 );
 $non_scottish_venues = eo_get_venues( array( 'meta_query' => $venue_query ) );

Note: You can query my any, and multiple, custom field keys. Venue address details are stored with the meta keys

  • _address
  • _city
  • _state
  • _postcode
  • _country
  • _lat
  • _lng

To get all venues in Edinburgh or Glasgow which have a bar

 $venue_query = array(
    array(
       'key' => '_city',
       'value' => array( 'Edinburgh', 'Glasgow' ),
       'compare' => 'IN'
    ),
    array(
       'key' => 'has_bar',
       'value' => 1,
    ),
 );
 $venues = eo_get_venues( array( 'meta_query' => $venue_query ) );

Proximity Queries

Since 1.2 (Pro) you can also query venues (or events at venues, see below) by their proximity to a given location. The ‘proximity query’ extends the meta_query component and each ‘proximity’ array can contain the following:

  • center (array) – Array index by ‘lat’ and’lng’
  • distance (int) – Optional. A distance from the center point.
  • unit (string) – ‘miles’ or ‘km’ (kilometres). Default: ‘miles’.
  • compare – how the query the venues by distance (e.g. venues which are less than X miles away, venues which are greater than X miles away etc). Possible values are ‘=’, ‘>’, ‘>=’, ‘<‘, ‘<=’. Default value is ‘<=’.

When the venue meta query includes a proximity query you can set ‘orderby’ to ‘distance’. If you wish to query all venues, but order them by a distance from some point, then you still need to include a proximity query – but you do not need to set a distance.

Examples

//Get venues within 10 miles of Windsor Castle, order by distance
$venue_query = array(
           'proximity' => array(
                'center' => eo_remote_geocode( "Windsor [castle]" ),
                'distance' => 10,
                'unit' => 'miles',
                'compare' => '<='
           ),
);

$venues = eo_get_venues( array( 
            'orderby' => 'distance', 
            'order' => 'ASC',
            'meta_query' => $venue_query 
          ));

Getting a location’s latititude/longtitude co-ordinates:

See the the documentation for function eo_remote_geocode()

Getting Events via Venue Queries

Event Organiser Pro allows you to retrieve events whose venue match a given query. Simply use the venue_query argument (which behaves very similarly to WordPress’ native meta_query argument ).

The venue_query is identical to the meta_query in eo_get_events() referred to above.

For instance to get all future events in the city of Edinburgh:

$edinburgh_events = new WP_Query( array( 
       'post_type' => 'event',
       'venue_query' => array( 
            array(
                'key' => '_city',
                'value' => 'Edinburgh'
            )
        ),
        'event_start_after' => 'today'
 ));

Note: the venue query will also work with eo_get_events() and get_posts().