Query Venue
Topics
This document is intended to demonstrate how each available argument can be used when querying the venues in the database using the ORM. The following arguments are available when querying venues in the database using the ORM. The ORM’s ->where() and ->by() options build SQL queries under the hood and return an array of venues in the form of WP Post Objects. In addition to all the base query arguments, these filters are available that are specific to venue posts.
‘has_events’
Filters venues that have events associated with them.
$results = tribe_venues()->where( 'has_events', true )->all();
‘has_no_events’
Filters venues that have no events associated with them.
$results = tribe_venues()->where( 'has_no_events', true )->all();
‘address’
Filters venues by their street address.
// Find venues with a specific address.
$results = tribe_venues()->where( 'address', '123 Main Street' )->all();
// Find venues containing address text (using LIKE).
$results = tribe_venues()->by( 'meta_like', '_VenueAddress', 'Broadway' )->all();
‘city’
Filters venues by their city.
// Find venues in a specific city.
$results = tribe_venues()->where( 'city', 'New York' )->all();
// Find venues in multiple cities.
$results = tribe_venues()->by( 'meta_in', '_VenueCity', [ 'New York', 'Los Angeles', 'Chicago' ] )->all();
‘state’, ‘province’, ‘state_province’
Filters venues by their state or province. All three arguments query the same field (_VenueStateProvince).
// Find venues in California.
$results = tribe_venues()->where( 'state', 'CA' )->all();
// Find venues in Ontario, Canada.
$results = tribe_venues()->where( 'province', 'ON' )->all();
// Find venues in multiple states/provinces.
$results = tribe_venues()->by( 'meta_in', '_VenueStateProvince', [ 'CA', 'NY', 'TX' ] )->all();
‘postal_code’, ‘zip’
Filters venues by their postal/zip code. Both arguments query the same field (_VenueZip).
// Find venues with specific zip code.
$results = tribe_venues()->where( 'zip', '90210' )->all();
// Find venues in zip code range (using LIKE for partial matches).
$results = tribe_venues()->by( 'meta_like', '_VenueZip', '902' )->all();
‘country’
Filters venues by their country.
// Find venues in the United States.
$results = tribe_venues()->where( 'country', 'United States' )->all();
// Find venues in multiple countries.
$results = tribe_venues()->by( 'meta_in', '_VenueCountry', [ 'United States', 'Canada', 'Mexico' ] )->all();
‘phone’
Filters venues by their phone number.
// Find venues with specific phone number. Note: The string will be formatted however it is entered when the venue was created.
$results = tribe_venues()->where( 'phone', '(555) 123-4567' )->all();
// Find venues with area code (using LIKE for partial matches).
$results = tribe_venues()->by( 'meta_like', '_VenuePhone', '555' )->all();
‘website’
Filters venues by their website URL.
// Find venues with specific website.
$results = tribe_venues()->where( 'website', 'https://example.com' )->all();
// Find venues with websites containing domain (using LIKE).
$results = tribe_venues()->by( 'meta_like', '_VenueURL', 'example.com' )->all();
Events Pro Geolocation Filters
The following filters are available when Events Pro is active and provide powerful geolocation-based venue querying capabilities.
‘has_geoloc’
Filters venues based on whether they have geolocation information (latitude and longitude coordinates).
// Find venues that have geolocation data.
$results = tribe_venues()->where( 'has_geoloc', true )->all();
// Find venues that don't have geolocation data.
$results = tribe_venues()->where( 'has_geoloc', false )->all();
‘geoloc_lat’
Filters venues by latitude coordinate, with optional distance radius. The unit type used will be the same as defined in the calendar settings.
// Find venues near latitude 40.7128 (New York City) within default 10 units.
$results = tribe_venues()->where( 'geoloc_lat', 40.7128 )->all();
// Find venues within 5 units of latitude.
$results = tribe_venues()->where( 'geoloc_lat', 40.7128, 5 )->all();
‘geoloc_lng’
Filters venues by longitude coordinate, with optional distance radius.
// Find venues near longitude -74.0060 (New York City) within default 10 units.
$results = tribe_venues()->where( 'geoloc_lng', -74.0060 )->all();
// Find venues within 5 units of longitude.
$results = tribe_venues()->where( 'geoloc_lng', -74.0060, 5 )->all();
‘geoloc’
Filters venues by both latitude and longitude coordinates, with optional distance radius. This creates a circular search area around the specified coordinates.
// Find venues near specific coordinates (NYC) within default 10 units.
$results = tribe_venues()->where( 'geoloc', 40.7128, -74.0060 )->all();
// Find venues within 25 units of coordinates.
$results = tribe_venues()->where( 'geoloc', 40.7128, -74.0060, 25 )->all();
‘near’
Filters venues that are geographically close to a provided address within a certain distance. This filter will be ignored if the address cannot be resolved to latitude and longitude coordinates.
// Find venues near Times Square within default 10 units.
$results = tribe_venues()->where( 'near', 'Times Square, New York, NY' )->all();
Complex Query Examples
You can combine multiple venue filters to create more specific queries:
// Find venues in California that have events.
$results = tribe_venues()
->where( 'state', 'CA' )
->where( 'has_events', true )
->all();
// Find venues near Los Angeles with websites.
$results = tribe_venues()
->where( 'near', 'Los Angeles, CA', 15 )
->by( 'meta_exists', '_VenueURL' )
->all();
// Find venues in multiple cities that have geolocation data.
$results = tribe_venues()
->by( 'meta_in', '_VenueCity', [ 'New York', 'Los Angeles', 'Chicago' ] )
->where( 'has_geoloc', true )
->all();