我正在创建一个Wordpress网站,该网站通过Eventbrite API显示事件。使用https://github.com/Automattic/eventbrite-api
中的API我能够获取数据。使用事件数据创建模板,并创建一个滑块。我想做的是按场所ID和组织者ID过滤这些事件。
到目前为止我所做的。
创建一个遍历事件的循环,并为每个循环输入。但是结果出来了,因为每个城市是一个单独的数组,所以每个城市都有一个单独的下拉列表。
<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>
以下代码
$result = array(eventbrite_event_venue());
echo print_r($result);
输出以下内容:
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
)
)
我不确定如何将数组合并为一个,当您选择城市时,变量应放入此处以过滤事件循环
<?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();
?>