WordPress元查询关系无法正常工作?

时间:2018-10-29 06:13:19

标签: mysql wordpress

请看一下我的代码。

$todayDate = strtotime(date('m/d/Y h:i:s'));
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(  
  'relation' => 'AND',
    array(
        'key' => 'featured_post',
        'value' => '1',
        'compare' => '==',          
    ),
    array(
       'key' => 'expiration_date',
       'value' => $todayDate,
       'compare' => '>',          
    ),      
)       
);

当我运行查询时,它的返回结果是没有feature_post = 1的帖子,这是怎么回事?我想对所有具有featured_post = 1且expiration_date比今天大的帖子进行排序? 有什么帮助吗? 谢谢

2 个答案:

答案 0 :(得分:1)

您需要使用单个=,它将被视为featured_post数组中的正确运算符,下面是一个示例

array(
    'key' => 'featured_post',
    'value' => '1',
    'compare' => '=',          
 )

答案 1 :(得分:0)

请先检查特色帖子

$todayDate = strtotime(date('m/d/Y h:i:s'));
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(  
  'relation' => 'AND',
    array(
        'key' => 'featured_post',
        'value' => '1',
        'compare' => '==',          
    ))
);