我正在为 wp_query 苦苦挣扎,我需要你的帮助。
我有 3 个自定义字段,分别称为“Agenda_day”、“Agenda_month”、“Agenda_year”,分别代表事件的日、月和年。
我想按天、按月、最后按年对查询结果进行升序排列。
这是我的查询:
$query_agenda = new WP_Query(
array(
'posts_per_page' => 8,
'cat' => 4,
'meta_query' =>
array(
'relation' => 'AND',
'day' => array('key' => 'Agenda_day', 'compare' => 'EXISTS'),
'month' => array('key' => 'Agenda_month', 'compare' => 'EXISTS'),
'year' => array('key' => 'Agenda_year', 'compare' => 'EXISTS')
),
'orderby' => array('day' => 'ASC', 'month' => 'ASC', 'year' => 'ASC')
)
);
这不起作用......你能解释一下为什么并告诉我如何解决它吗?
谢谢 !
编辑
这是执行的查询(返回结果但排序不正确)
从 wp_posts 中选择 SQL_CALC_FOUND_ROWS wp_posts.ID 左连接 wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = INNER JOIN). wp_postmeta AS mt2 ON (wp_posts.ID = mt2.post_id) WHERE 1=1 AND (wp_term_relationships.term_taxonomy_id IN (4)) AND (wp_postmeta.meta_key = 'Agenda_jour' AND mt1.meta_key = 'Agenda_mois' AND mt2.meta_key = ' Agenda_annee' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY CAST(wp_postmeta.meta_value AS CHAR) ASC, CAST(mt1. meta_value AS CHAR) ASC, CAST(mt2.meta_value AS CHAR) ASC LIMIT 0, 8