【发布时间】:2011-02-22 03:13:31
【问题描述】:
我需要检索包含(至少)一个附件属于 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 知道“谁”在查询中包含了该帖子。
【问题讨论】:
-
@PieterGoosen 我有点不同意你对这个问题的编辑/扩展。供您参考I submitted it for review on meta。
-
@RandomSeed - 我同意。这个问题现在措辞完全不同。
-
“附件.ID”。这是 bma_posts.ID 吗?如果是这样,那将存在于 Select 子句中。也不清楚“谁”的来源。什么表中的哪一列?