gpt4 book ai didi

php - WordPress:如何使用自定义查询获取不包含特定类别的帖子

转载 作者:行者123 更新时间:2023-11-29 12:10:19 25 4
gpt4 key购买 nike

我需要显示所有不包含特定类别的帖子。我使用以下查询,但我还检索包含类别 81 的帖子,因为该帖子还包含其他类别。有办法解决吗?

SELECT p1.*, wm2.meta_value 
FROM wp_posts p1
LEFT JOIN wp_postmeta wm1 ON (
wm1.post_id = p1.id
AND wm1.meta_value IS NOT NULL
AND wm1.meta_key = '_thumbnail_id'
)
LEFT JOIN
wp_postmeta wm2
ON (
wm1.meta_value = wm2.post_id
AND wm2.meta_key = '_wp_attached_file'
AND wm2.meta_value IS NOT NULL
)
LEFT JOIN
wp_term_relationships wtr
ON (
object_id=p1.id
)
WHERE
p1.post_status='publish'
AND p1.post_type='post'
AND `term_taxonomy_id`<>81
GROUP BY ID
ORDER BY p1.post_date DESC
LIMIT 0,10

谢谢!

最佳答案

这应该有效

SELECT p1.*, wm2.meta_value 
FROM wp_posts p1
LEFT JOIN wp_postmeta wm1 ON (
wm1.post_id = p1.id
AND wm1.meta_value IS NOT NULL
AND wm1.meta_key = '_thumbnail_id'
)
LEFT JOIN
wp_postmeta wm2
ON (
wm1.meta_value = wm2.post_id
AND wm2.meta_key = '_wp_attached_file'
AND wm2.meta_value IS NOT NULL
)
LEFT JOIN
wp_term_relationships wtr
ON (
object_id=p1.id
)
WHERE
p1.post_status='publish'
AND p1.post_type='post'
AND object_id NOT IN (SELECT `object_id` FROM wp_term_relationships where `term_taxonomy_id`=81)
GROUP BY ID
ORDER BY p1.post_date DESC
LIMIT 0,10

关于php - WordPress:如何使用自定义查询获取不包含特定类别的帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30822037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com