php - 弄清楚如何为过滤器循环合并数组
问题描述
我正在创建一个通过 Eventbrite API 显示事件的 Wordpress 网站。使用来自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();
?>
解决方案
推荐阅读
- kubernetes - 当 kubernetes pod 在协调过程中崩溃并且协调失败时,有没有办法让它完成协调?
- javascript - 函数意外更改参数值
- python - 检查列表元素是 < 一个值,做一些事情 - 似乎无法解决
- node.js - 一个名为“-”的节点包被无意中添加到我的 package.json 中?
- angular - Angular - 具有嵌套 FormGroup 的组件中的表单控件没有值访问器
- python-3.x - 当测试必须应用于 text_content 而不是文本时,lxml.html 元素的 XPATH 表达式
- jquery - 验证字段,使其不接受空格和特殊字符
- php - 使用 PHP 调用 Coinmarketcap API
- latex - 乳胶:带有标题的警告
- linux - Bash 脚本在 SFTP 下载期间终止