我有自定义的post类型事件,它具有自定义字段event\\u date。此字段的日期格式设置为Ymd。
我正在尝试按event\\u日期的顺序获取帖子
以下是按此顺序拉柱的代码
$today = date(\'Ymd\');
$args = array (
\'post_type\' => array( \'event\' ),
\'posts_per_page\' => \'-1\',
\'order\' => \'ASC\',
\'orderby\' =>\'meta_value\', // also tried having meta_value_num but that didn\'t worked as well
\'meta_key\' =>\'event_date\',
\'meta_query\' => array(
array(
\'key\' => \'event_date\',
\'compare\' => \'>=\',
\'value\' => $today,
)
),
\'suppress_filters\' => true
);
/*
global $wp_filter;
var_dump( $wp_filter[\'posts_orderby\'] );die;
This returns NULL as well
*/
$query = new WP_Query( $args );
echo \'<pre>\';
var_dump($query->request);die;
但是$query->请求将订单显示为post\\u date,比我提供的查询快。这是请求的转储
string(681) "SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id ) WHERE 1=1 AND (
wp_posts.ID NOT IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id IN (11)
)
) AND (
wp_postmeta.meta_key = \'event_date\'
AND
(
( mt1.meta_key = \'event_date\' AND mt1.meta_value >= \'20171113\' )
)
) AND wp_posts.post_type = \'event\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'acf-disabled\' OR wp_posts.post_status = \'private\') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date ASC "
无法按event\\u日期排序。我做错了什么??甚至尝试过
remove_all_filters(\'posts_orderby\');
之前的wp\\u查询结果仍然相同。
注意:在stackoverflow中发布了此内容,但无法获得答案,因此这是一个重新发布。