我正在尝试编写一个查询来检查保存时自定义帖子类型(属性)中的自定义元值是否等于另一个自定义帖子类型中的元值(警报)
我可以为正常匹配字段完成这项工作,但是我试图让它在一个范围内工作,例如,如果“属性”中的“卧室”介于“警报”中的“a_bedrooms_min”和“a_bedrooms_max”之间。到目前为止,我的查询看起来像这样:
//Property Meta Fields
$meta_type = 'flat';
$meta_bedrooms = '2';
//Alert Meta Fields
a_bedrooms_min = 1
a_bedrooms_max = 3
SELECT ID
FROM wp_posts
INNER JOIN wp_postmeta m1
ON ( wp_posts.ID = m1.post_id )
INNER JOIN wp_postmeta m2
ON ( wp_posts.ID = m2.post_id )
INNER JOIN wp_postmeta m3
ON ( wp_posts.ID = m3.post_id )
WHERE
wp_posts.post_type = 'alerts'
AND wp_posts.post_status = 'publish'
AND ( m1.meta_key = 'a_property_type' AND m1.meta_value = '$meta_type' )
AND ( m2.meta_key = 'a_bedrooms_min' AND m2.meta_value >= '$meta_bedrooms' )
AND ( m3.meta_key = 'a_bedrooms_max' AND m3.meta_value <= '$meta_bedrooms' )
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date
DESC;
最后两个 AND 显然不适用于我正在尝试做的事情,但如何才能让它发挥作用?
谢谢罗伯特