tribe_get_venues( bool $only_with_upcoming = false, int $posts_per_page = -1, bool $suppress_filters = true, array $args = array() )
Get all the venues
Contents
Parameters
- $only_with_upcoming
-
(bool) (Optional) Only return venues with upcoming events attached to them.
Default value: false
- $posts_per_page
-
(int) (Optional)
Default value: -1
- $suppress_filters
-
(bool) (Optional)
Default value: true
- $args
-
(array) (Optional) Array of Query parameters.
- 'event'
(int) Only venues linked to this event post ID. - 'has_events'
(bool) Only venues that have events. - 'found_posts'
(bool) Return the number of found venues.
Default value: array()
- 'event'
Return
(array) An array of venue post objects.
Source
File: src/functions/template-tags/venue.php
function tribe_get_venues( $only_with_upcoming = false, $posts_per_page = -1, $suppress_filters = true, array $args = array() ) {
// filter out the `null` values
$args = array_diff_key( $args, array_filter( $args, 'is_null' ) );
if ( tribe_is_truthy( $only_with_upcoming ) ) {
$args['only_with_upcoming'] = true;
}
$filter_args = array(
'event' => 'find_for_event',
'has_events' => 'find_with_events',
'only_with_upcoming' => 'find_with_upcoming_events',
);
foreach ( $filter_args as $filter_arg => $method ) {
if ( ! isset( $args[ $filter_arg ] ) ) {
continue;
}
if ( 'only_with_upcoming' !== $filter_arg ) {
$found = tribe( 'tec.linked-posts.venue' )->$method( $args[ $filter_arg ] );
} else {
$found = tribe( 'tec.linked-posts.venue' )->find_with_upcoming_events(
$args[ $filter_arg ],
isset( $args['post_status'] ) ? $args['post_status'] : null
);
}
if ( empty( $found ) ) {
return array();
}
$args['post__in'] = ! empty( $args['post__in'] )
? array_intersect( (array) $args['post__in'], $found )
: $found;
if ( empty( $args['post__in'] ) ) {
return array();
}
}
$parsed_args = wp_parse_args( $args, array(
'post_type' => Tribe__Events__Main::VENUE_POST_TYPE,
'posts_per_page' => $posts_per_page,
'suppress_filters' => $suppress_filters,
)
);
$return_found_posts = ! empty( $args['found_posts'] );
if ( $return_found_posts ) {
$parsed_args['posts_per_page'] = 1;
$parsed_args['paged'] = 1;
}
$query = new WP_Query( $parsed_args );
if ( $return_found_posts ) {
if ( $query->have_posts() ) {
return $query->found_posts;
}
return 0;
}
return $query->have_posts() ? $query->posts : array();
}
Changelog
| Version | Description |
|---|---|
| 6.2.9 | Introduced. |