Php 两个日期之间的Wordpress搜索
我已经在两个日期之间创建了自定义帖子搜索。它的工作和显示的结果,但有一个问题。它没有显示精确的搜索结果 例如:如果我将20-3-2013添加到27-3-2013,它将显示其他日期和月份的有线结果。它完全没有得到确切的价值 这是我的密码。phpPhp 两个日期之间的Wordpress搜索,php,sql,wordpress,Php,Sql,Wordpress,我已经在两个日期之间创建了自定义帖子搜索。它的工作和显示的结果,但有一个问题。它没有显示精确的搜索结果 例如:如果我将20-3-2013添加到27-3-2013,它将显示其他日期和月份的有线结果。它完全没有得到确切的价值 这是我的密码。php <?php function getCatSearchFilter($pre,$post){ $category = ""; $catId = htmlspecialchars($_GET["cat"]); if ($catId != null &a
<?php
function getCatSearchFilter($pre,$post){
$category = "";
$catId = htmlspecialchars($_GET["cat"]);
if ($catId != null && $catId != '' && $catId != '0'){
$category = $pre.get_cat_name($catId).$post;
}
return $category;
}
?>
<?php
$search_word="";
if(!empty($_REQUEST['s'])){
$name_word=$_REQUEST['s'];
$search_word="(post_title LIKE \"%$name_word%\" or post_content LIKE \"%$name_word%\") and ";
}
//if(!empty($_REQUEST['d']) && $_REQUEST['d'] != 'von'){
if(!empty($_REQUEST['sDate'])){
$s_name_date=$_REQUEST['sDate'];
$s_custom_date1 = substr($s_name_date,0,2);
$s_custom_date2 = substr($s_name_date,3,2);
$s_custom_date3 = substr($s_name_date,6,4);
$s_name_date = "$s_custom_date3.$s_custom_date2.$s_custom_date1";
//$search_word.="post_date LIKE \"%$name_date%\" and ";
if(!empty($_REQUEST['eDate'])){
$e_name_date=$_REQUEST['eDate'];
$e_custom_date1 = substr($e_name_date,0,2);
$e_custom_date2 = substr($e_name_date,3,2);
$e_custom_date3 = substr($e_name_date,6,4);
$e_name_date = "$e_custom_date3.$e_custom_date2.$e_custom_date1";
//$where .= " AND post_date >= '$s_name_date' AND post_date < '$e_name_date'";
$where .= "AND pm.meta_key='custom_time_from' and pm.meta_value >= '$s_name_date'
and pm.meta_value < '$e_name_date'";
}
}
if($_REQUEST['cat']){
$categoryId = $_REQUEST['cat'];
$search_word.="ID in (select p.ID from $wpdb->terms c,$wpdb->term_taxonomy tt,$wpdb->term_relationships tr,$wpdb->posts p ,$wpdb->postmeta t where c.term_id like '".$categoryId."' and c.term_id=tt.term_id and tt.term_taxonomy_id=tr.term_taxonomy_id and tr.object_id=p.ID and p.ID = t.post_id and p.post_status = 'publish' group by p.ID) and";
}
if($where)
{
$query ="select p.* from wp_posts p
join wp_postmeta pm on p.ID=pm.post_id
WHERE p.post_status='publish' and p.post_type='post' $where";
}
else
{
$query="select * from wp_posts WHERE $search_word post_status='publish'";
}
$pageposts=$wpdb->get_results($query, OBJECT);
if ($pageposts):
global $post;
foreach ($pageposts as $post):
setup_postdata($post);
?>
<?php if($post->post_type=='post')
{
?>
摘自以下链接
你应该考虑阅读WordPress文档,关于如何使用<代码> $WPDB和其他伟大的功能。这是很多代码,并要求首先进行基本调试。您是否查看了向查询提供日期的格式?您知道正确的格式是YYYY-MM-DD
?我检查了日期格式问题,这不是日期格式的问题
<div id="search">
<form method="get" id="searchform" action="" >
<input id="s" style="" type="text" name="s" placeholder="search" value="" />
<input style="width:95px; " type="text" name="sDate" class="datepicker" placeholder="from" />
<input style="width:95px;" type="text" name="eDate" class="datepicker" placeholder="to" />
// Set arguments for events
$start = '2011-11-31';
$end = '2011-10-01';
$args = array(
'post_type' => 'my-event-type',
'posts_per_page' => -1,
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => '_my-datetime-from',
'meta_query' => array(
array(
'key' => '_my-datetime-from',
'value' => array($start, $end),
'compare' => 'BETWEEN',
'type' => 'DATE'
)
)
);
// Make the query
$events_query = new WP_query();
$events_query->query($args);