自定义帖子类型—
事件
自定义分类法—
–
myevents
使用jQuery Datepicker作为开始日期和结束日期
用于搜索事件名称的搜索字段
文章图片
我想通过使用简单的表单搜索来获取自定义帖子类型事件。在其中, 我在select选项中获取了自定义分类法, 然后在最后一个Search字段中使用jQuery Datepicker添加了开始日期和结束日期。
我的搜索网址如下所示:
http://localhost/customthemedev/?categoryfilter=Techfest&
Start=01-May-2019&
End=10-May-2019&
search=smoke+event+
<
form class="select-event-date" method="GET" action="<
?php bloginfo('home');
?>
" autocomplete="off" id="filter">
<
div class="form-group eventfunction">
<
label>
Categories<
/label>
<
select class="form-control" name="categoryfilter">
<
?php
$tax_terms = get_terms('myevents', array('hide_empty' =>
'0'));
foreach ( $tax_terms as $tax_term ):
echo '<
option value="'.$tax_term->
name.'">
'.$tax_term->
name.'<
/option>
';
endforeach;
?>
<
/select>
<
/div>
<
div class="form-group selectDate">
<
input type="text" class="form-control" placeholder="Start Date" name="Start" id="txtFrom">
<
/div>
<
div class="form-group endDate">
<
input type="text" class="form-control" placeholder="End Date" name="End"id="txtTo">
<
/div>
<
div class="form-group searchEvent">
<
label>
<
img src="http://www.srcmini.com/<
?php echo get_template_directory_uri();
;
?>
/assets/images/search-22.png" alt="Icon">
<
/label>
<
input type="text" placeholder="Search.." name="search">
<
/div>
<
button type="submit" class="btn btn-default">
FIND EVENTS<
/button>
<
/form>
#1
Try this :
【如何根据自定义分类,开始日期和结束日期以及在wordpress中的搜索输入来获取帖子()】//以数组格式获取所有术语
$termSlug = array();
$tax_terms = get_terms('myevents', array('hide_empty' =>
'0'));
foreach ( $tax_terms as $tax_term ):
$termSlug[] = $tax_term->
slug;
endforeach;
//Assign the date into variable $start_date = '01-May-2019';
$end_date ='10-May-2019';
//use the date format acccording to SQL format$start_date_new = date("YOUR DATE FORMAT", strtotime($start_date));
$end_date_new = date("YOUR DATE FORMAT", strtotime($end_date));
$event_args = array(
'post_type' =>
'Event', //Post type event
'orderby' =>
'date', 'order' =>
'DESC', 'posts_per_page' =>
-1, 'meta_query'=>
array(//Meta Query search
'relation'=>
'AND', array(
'key' =>
'start_date', 'value' =>
$start_date_new, //start date here
'compare' =>
'>
=', 'type' =>
'NUMERIC'
), array(
'key' =>
'end_date', 'value' =>
$end_date_new, //end date here
'compare' =>
'<
=', 'type' =>
'NUMERIC'
)
), 'tax_query' =>
array(
array (
'taxonomy' =>
'myevents', //Taxonomy search
'field' =>
'slug', 'terms' =>
$termSlug, //terms in array
)
), );
$all_events = new WP_Query($event_args);
echo '<
pre>
';
print_r($all_events);
echo '<
/pre>
';
推荐阅读
- 如何在WordPress中通过查找HTML渲染()
- 如何查找和编辑登录的”php页面”以及更改详细信息
- 如何延长团队成员的排序顺序
- 如何从WordPress中的子主题扩展类()
- 如何从搜索结果中排除wordpress页面模板(自定义模板)()
- 如何确保短代码结果不会破坏格式()
- 圆满者U盘维护系统最新推荐
- 分区工具diskgenius最新推荐
- U盘修好工具最新推荐