由于我们没有为此蒙皮或使用标准模板,我们遇到了一些困难,但我们在项目中走得太远,无法回头。我从来没有这样做过WP\\U查询,但有两件事可以概括它的结构。
我正在查询帖子类型tribe_events
其中postmeta密钥等于_VenueCity
, _VenueState
, 和_VenueCountry
和值等于GET/POST请求邮戳被分配给tribe_venue
分类法使我很难直接查询Posteta,因为它没有直接连接到tribe_events
岗位类型我尝试了很多事情,但这是我许多不同努力的结果。
<?php
// Support for multiple locations to be filtered.
$request_cities = array_map(function($item){return utf8_decode(urldecode($item));}, explode(\'+\', $_REQUEST[\'city\']));
$request_states = array_map(function($item){return utf8_decode(urldecode($item));}, explode(\'+\', $_REQUEST[\'state\']));
$request_countries = array_map(function($item){return utf8_decode(urldecode($item));}, explode(\'+\', $_REQUEST[\'country\']));
// If the event only has 1 item convert to string.
if (is_array($request_cities) && count($request_cities) <= 1) {
$request_cities = implode("|", $request_cities);
}
if (is_array($request_states) && count($request_states) <= 1) {
$request_states = implode("|", $request_states);
}
if (is_array($request_countries) && count($request_countries) <= 1) {
$request_countries = implode("|", $request_countries);
}
$event_args = [];
$event_args[\'meta_query\'] = [
[
\'key\' => \'_VenueCity\',
\'value\' => $request_cities
], [
\'key\' => \'_VenueState\',
\'value\' => $request_states
], [
\'key\' => \'_VenueCountry\',
\'value\' => $request_countries
],
\'relation\' => \'AND\'
];
$event_args[\'tax_query\'] = [
[
\'taxonomy\' => \'tribe_venue\',
\'field\' => \'term_id\',
\'terms\' => $request_cities
]
];
$events = tribe_get_events($event_args);
?>
如果有人能帮我弄明白这一点,我将不胜感激,因为我花了这么多时间试图弄明白这一点。
最合适的回答,由SO网友:Stephen Sabatini 整理而成
因此,在从活动日历的网站上进行了大量搜索之后,我找到了解决方案,并对其进行了修改以满足我的需要。代码如下所示:(注意,我还删除了数组到字符串的转换,因为它非常无意义。)
<?php
// Support for multiple locations to be filtered.
$request_cities = array_map(function($item){return utf8_decode(urldecode($item));}, explode(\'+\', $_REQUEST[\'city\']));
$request_states = array_map(function($item){return utf8_decode(urldecode($item));}, explode(\'+\', $_REQUEST[\'state\']));
$request_countries = array_map(function($item){return utf8_decode(urldecode($item));}, explode(\'+\', $_REQUEST[\'country\']));
//Retrieve venues that match query criteria
$args = [
\'nopaging\' => true,
\'post_type\' => \'tribe_venue\',
\'meta_query\' => [
[
\'key\' => \'_VenueCity\',
\'value\' => $request_cities,
\'compare\' => \'IN\',
], [
\'key\' => \'_VenueState\',
\'value\' => $request_states,
\'compare\' => \'IN\',
], [
\'key\' => \'_VenueCountry\',
\'value\' => $request_countries,
\'compare\' => \'IN\',
],
\'relation\' => \'AND\'
]
];
$venues = get_posts($args);
$venue_ids = wp_list_pluck($venues, \'ID\');
wp_reset_postdata();
$event_args[] = [
\'meta_query\' => [
[
\'key\' => \'_EventVenueID\',
\'value\' => $venue_ids,
\'compare\' => \'IN\',
]
],
\'paged\' => $paged
];
$events = tribe_get_events($event_args);
?>
资料来源:
https://theeventscalendar.com/support/forums/topic/events-list-with-filter-by-venue-in-custom-template/#post-1290489