我正在尝试在 Wordpress 中设置警报,以便用户可以创建警报,以便在创建的新帖子(属性)符合他们设定的标准(警报)时收到通知。我的计划是使用两种帖子类型来做到这一点,一种用于属性,一种用于警报。然后,当保存属性帖子时,它将执行以下示例查询:
SELECT
post_author
FROM
wp_posts
INNER JOIN wp_postmeta m1
ON wp_posts.ID = m1.post_id
AND m1.meta_key = 'a_property_type'
AND m1.meta_value = 'flat'
INNER JOIN wp_postmeta m2
on wp_posts.ID = m2.post_id
AND m2.meta_key = 'a_bedrooms_min'
AND m2.meta_value <= '2'
INNER JOIN wp_postmeta m3
on wp_posts.ID = m3.post_id
AND m3.meta_key = 'a_bedrooms_max'
AND m3.meta_value >= '2'
INNER JOIN wp_postmeta m4
on wp_posts.ID = m4.post_id
AND m4.meta_key = 'a_bathrooms_min'
AND m4.meta_value <= '2'
INNER JOIN wp_postmeta m5
on wp_posts.ID = m5.post_id
AND m5.meta_key = 'a_bathrooms_max'
AND m5.meta_value >= '2'
INNER JOIN wp_postmeta m6
on wp_posts.ID = m6.post_id
AND m6.meta_key = 'a_garden'
AND m6.meta_value >= '1'
INNER JOIN wp_postmeta m7
on wp_posts.ID = m7.post_id
AND m7.meta_key = 'a_garage'
AND m7.meta_value >= '1'
INNER JOIN wp_postmeta m8
on wp_posts.ID = m8.post_id
AND m8.meta_key = 'a_parking'
AND m8.meta_value >= '1'
INNER JOIN wp_postmeta m9
on wp_posts.ID = m9.post_id
AND m9.meta_key = 'a_double_glazing'
AND m9.meta_value >= '1'
INNER JOIN wp_postmeta m10
on wp_posts.ID = m10.post_id
AND m10.meta_key = 'a_country'
AND m10.meta_value LIKE 'Scotland'
WHERE
wp_posts.post_type = 'alerts'
AND wp_posts.post_status = 'publish'
GROUP BY
wp_posts.ID
ORDER BY
wp_posts.post_date DESC
这有效并且确实返回匹配标准集的属性,但是当我引入 LIKE 时,它确实使查询挂起。我正在使用默认的 Wordpress 表“wp_posts”和“wp_postmeta”。我尝试在“meta_value”列上设置索引,但因为它是一个“longtext”字段,它不允许我这样做。
是否有更好的解决方案可以做到这一点,或者我的查询可以更有效地编写?
谢谢