gpt4 book ai didi

sql - 在特定类别中获取带有附件的帖子?

转载 作者:行者123 更新时间:2023-11-29 03:14:30 25 4
gpt4 key购买 nike

我需要检索包含(至少)一个属于 WordPress 类别的附件的帖子列表。

我用WordPress默认方法自己做的附件和分类的关系。

这是我现在正在运行的查询:

SELECT post.*
FROM `bma_posts` AS post
WHERE
EXISTS (
SELECT 1
FROM `bma_posts` AS attachment
JOIN `bma_term_relationships` AS relationship ON
relationship.`object_id` = attachment.`ID`
AND
relationship.`term_taxonomy_id` IN (17,15,16,5)
WHERE
attachment.`post_parent` = post.`ID`
AND
attachment.`post_type` = 'attachment'
)
AND
post.`post_type` = 'post'
AND
post.`post_status` = 'publish'
ORDER BY post.`post_date` DESC
LIMIT 3

现在的问题是我无法获取附件。ID 以了解“谁”在查询中包含该帖子。

最佳答案

Select ...
From wp_posts As P
Where Exists (
Select 1
From wp_posts As P1
Join wp_term_relationship As WTR1
On WTR1.object_id = P1.ID
And WTR1.term_taxonomy_id In(3)
Where P1.post_parent = P.Id
And P1.post_type = 'attachment'
)
And P.post_type = 'post'
Order By p.post_date DESC
Limit 15

关于sql - 在特定类别中获取带有附件的帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2878432/

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