I am creating a Wordpress website that shows events through the Eventbrite API. Using the API from https://github.com/Automattic/eventbrite-api
I was able to get the data. create a template with the events data and create a slider too. What I am trying to do is filter these events by venue id and organizer id.
What I have done so far.
Created a loop that goes through the events and inputs the for each loop. But it comes out as each city is a separate array so a separate drop down for each city.
<div id="venues" class="form-group my-5">
<form
id="venue-select"
class="venue-select input-group-prepend ml-auto mt-5"
action="<?php echo esc_url(home_url('/')); ?>"
method="get"
>
<?php printf(eventbrite_event_venue()); ?>
<?php
// Set up and call our Eventbrite query.
$venue_filter = new Eventbrite_Query(apply_filters( 'eventbrite_query_args', array(
'display_private' => true, // boolean)
'status' => 'live', // string (only available for display_private true)
'limit' => 100, // integer
)));
if ($venue_filter->have_posts()) :
while ($venue_filter->have_posts()) : $venue_filter->the_post();
$result = array(eventbrite_event_venue());
echo print_r($result);
$venues = array_merge($result);
$venues_array = array('Choose A City');
$get_venues = $venues;
foreach ( $get_venues as $venue ) {
$venues_array[] .= $venue;
}
$venue_id = array_unique($venues_array);
printf('<select name="%s" class="postform form-control">', esc_attr($venue));
foreach($get_venues as $venue) {
printf( '<option value="%s">%s</option>', esc_attr( $venue), esc_html(eventbrite_event_venue()->address->city ) );
}
print('</select>');
endwhile;
endif;
wp_reset_postdata();
wp_reset_query();
?>
</select>
</form>
</div>
The following code
$result = array(eventbrite_event_venue());
echo print_r($result);
outputs the following:
Array
(
[0] => stdClass Object
(
[address] => stdClass Object
(
[address_1] => 350 5th Avenue,
[address_2] => 5th Floor, The LAB
[city] => New York
[region] => NY
[postal_code] => 10118
[country] => US
[latitude] => 40.7353956
[longitude] => -73.99462499999998
[localized_address_display] => 350 5th Avenue, 5th
Floor, The LAB, New York, NY 10118
[localized_area_display] => New York, NY
[localized_multi_line_address_display] => Array
(
[0] => 350 5th Avenue
[1] => 5th Floor, The LAB
[2] => New York, NY 10118
)
)
[resource_uri] =>
https://www.eventbriteapi.com/v3/venues/25816848/
[id] => 25816848
[age_restriction] =>
[capacity] =>
[name] => Global Brands Group
[latitude] => 40.7353956
[longitude] => -73.99462499999998
)
)
1Array
(
[0] => stdClass Object
(
[address] => stdClass Object
(
[address_1] => 350 5th Avenue,
[address_2] => 5th Floor, HR Training Room
[city] => New York
[region] => NY
[postal_code] => 10118
[country] => US
[latitude] => 40.7484799
[longitude] => -73.98542450000002
[localized_address_display] => 350 5th Avenue, 5th Floor, HR Training Room, New York, NY 10118
[localized_area_display] => New York, NY
[localized_multi_line_address_display] => Array
(
[0] => 350 5th Avenue
[1] => 5th Floor, HR Training Room
[2] => New York, NY 10118
)
)
[resource_uri] => https://www.eventbriteapi.com/v3/venues/25536431/
[id] => 25536431
[age_restriction] =>
[capacity] =>
[name] => Global Brands Group
[latitude] => 40.7484799
[longitude] => -73.98542450000002
)
)
1Array
(
[0] => stdClass Object
(
[address] => stdClass Object
(
[address_1] => 350 5th Avenue,
[address_2] => 5th Floor, HR Training Room
[city] => New York
[region] => NY
[postal_code] => 10118
[country] => US
[latitude] => 40.7484799
[longitude] => -73.98542450000002
[localized_address_display] => 350 5th Avenue, 5th Floor, HR Training Room, New York, NY 10118
[localized_area_display] => New York, NY
[localized_multi_line_address_display] => Array
(
[0] => 350 5th Avenue
[1] => 5th Floor, HR Training Room
[2] => New York, NY 10118
)
)
[resource_uri] => https://www.eventbriteapi.com/v3/venues/25536431/
[id] => 25536431
[age_restriction] =>
[capacity] =>
[name] => Global Brands Group
[latitude] => 40.7484799
[longitude] => -73.98542450000002
)
)
1Array
(
[0] => stdClass Object
(
[address] => stdClass Object
(
[address_1] => 350 5th Avenue,
[address_2] => 5th Floor, HR Training Room
[city] => New York
[region] => NY
[postal_code] => 10118
[country] => US
[latitude] => 40.7484799
[longitude] => -73.98542450000002
[localized_address_display] => 350 5th Avenue, 5th Floor, HR Training Room, New York, NY 10118
[localized_area_display] => New York, NY
[localized_multi_line_address_display] => Array
(
[0] => 350 5th Avenue
[1] => 5th Floor, HR Training Room
[2] => New York, NY 10118
)
)
[resource_uri] => https://www.eventbriteapi.com/v3/venues/25536431/
[id] => 25536431
[age_restriction] =>
[capacity] =>
[name] => Global Brands Group
[latitude] => 40.7484799
[longitude] => -73.98542450000002
)
)
1Array
(
[0] => stdClass Object
(
[address] => stdClass Object
(
[address_1] => 350 5th Avenue,
[address_2] => 5th Floor, HR Training Room
[city] => New York
[region] => NY
[postal_code] => 10118
[country] => US
[latitude] => 40.7484799
[longitude] => -73.98542450000002
[localized_address_display] => 350 5th Avenue, 5th Floor, HR Training Room, New York, NY 10118
[localized_area_display] => New York, NY
[localized_multi_line_address_display] => Array
(
[0] => 350 5th Avenue
[1] => 5th Floor, HR Training Room
[2] => New York, NY 10118
)
)
[resource_uri] => https://www.eventbriteapi.com/v3/venues/25536431/
[id] => 25536431
[age_restriction] =>
[capacity] =>
[name] => Global Brands Group
[latitude] => 40.7484799
[longitude] => -73.98542450000002
)
)
I am not sure how to merge the array into one and when you select the city, the variable should go into here to filter loop for the events
<?php
// Set up and call our Eventbrite query.
$events = new Eventbrite_Query( apply_filters(
'eventbrite_query_args', array(
'display_private' => true, // boolean
'status' => 'live', // string (only available for
display_private true)
'nopaging' => true, // boolean
'limit' => 100, // integer
//'organizer_id' => $organizerfilter, // integer
// 'p' => null, // integer
// 'post__not_in' => null, // array of integers
'venue_id' => $venue, // integer
// 'category_id' => null, // integer
// 'subcategory_id' => null, // integer
// 'format_id' => null, // integer
) ) );
if ( $events->have_posts() ) :
while ( $events->have_posts() ) : $events->the_post(); ?>
<?php get_template_part( 'template-parts/content', 'events' ); ?>
<?php endwhile;
// Previous/next post navigation.
eventbrite_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
// Return $post to its rightful owner.
wp_reset_query();
?>