我有这样一个自定义字段:
$myDate = usp_get_meta(false, \'usp-custom-51\');
这给了我这样的日期:
22/2/2011
然后我创建一个循环,首先检查$s
通过GET
在任何category
如果是,则显示其post
while ( have_posts() ) : the_post();
if($sel === "tema") {
$terms = get_terms( \'category\', array(
\'name__like\' => $s,
\'category__not_in\' => 183,
\'include_children\' => false,
\'hide_empty\' => true,
\'post_type\' => \'post\'
) );
if ( count($terms) > 0 ){
?>
<li>Lorem...</li>
这很有效,我可以看到帖子。但现在我需要再次检查发现的帖子是否在特定日期之间:
所以我有:
$start = $_GET[\'start\'];
$end = $_GET[\'end\'];
这给了我:
22/2/2011 and 15/7/2015
现在,我正在尝试创建一个新的查询,检查帖子是否在以下日期内:
$newId = get_cat_ID();
$args = array(
\'cat\' => $cat_ID,
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => $myDate,
\'value\' => $start,
\'compare\' => \'>=\',
\'type\' => \'DATE\'
),
array(
\'key\' => $myDate,
\'value\' => $end,
\'compare\' => \'<=\',
\'type\' => \'DATE\'
)
),
\'orderby\' => \'date\',
\'order\' => \'DESC\'
);
$events_query = new WP_query();
$events_query->query($args);
if( $events_query->have_posts() ) : while( $events_query->have_posts() ) : $events_query->the_post(); ?>
<li>Lorem...</li>
但这给了我零结果。
我试过:
\'meta_query\' => array(
array(
\'key\' => $myDate,
\'value\' => array($start, $end),
\'compare\' => \'BETWEEN\',
\'type\' => \'DATE\'
),
)
我尝试使用一个查询,如:
while ( have_posts() ) : the_post();
if($sel === "tema") {
$terms = get_terms( \'category\', array(
\'name__like\' => $s,
\'category__not_in\' => 183,
\'include_children\' => false,
\'hide_empty\' => true,
\'post_type\' => \'post\',
\'meta_query\' => array (
array(
\'key\' => $myDate,
\'value\' => array($start, $end),
\'compare\' => \'BETWEEN\',
\'type\' => \'DATE\'
),
)
) );
if ( count($terms) > 0 ){
?>
<li>Lorem...</li>
但仍然没有结果。
有什么想法吗?