我有一个名为Faculty的自定义帖子类型。它们可以是MCT、MLT或MT类型的任何一种。
MCT -> A, B
MLT -> C, E
MT -> C, D
我想在一页上按姓氏->C、D、e的顺序列出所有MLT和MT教员
我在orderby中使用OR时遇到了一个问题,它返回的是所有MLT或MT或姓氏(即everyone)的教员。AND关系正常工作,只返回C。
我的WP\\u查询参数是:
Array(
[post_type] => faculty
[order] => ASC
[orderby] => meta_value
[meta_key] => faculty_last_name
[meta_query] => Array(
[relation] => OR
[0] => Array(
[key] => faculty_MLT
[value] => MLT
[compare] => =
)
[1] => Array(
[key] => faculty_MT
[value] => MT
[compare] => =
)
)
)
创建的SQL是:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 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)
INNER JOIN wp_postmeta AS mt2 ON (wp_posts.ID = mt2.post_id)
WHERE 1=1 AND wp_posts.post_type = \'faculty\' AND (wp_posts.post_status = \'publish\'
OR wp_posts.post_status = \'private\')
AND (wp_postmeta.meta_key = \'faculty_last_name\'
-->OR (mt1.meta_key = \'faculty_MLT\' AND CAST(mt1.meta_value AS CHAR) = \'MLT\')
OR (mt2.meta_key = \'faculty_MT\' AND CAST(mt2.meta_value AS CHAR) = \'MT\') )
GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value ASC LIMIT 0, 10
如果将-->或更改为和,查询将返回正确的结果。
是否有某种方法可以将orderby与relation=>一起使用,或者在wp\\u查询中使用?