は次のようになります。フィルタポスト、彼らは唯一の特定のタグを持っている場合
SELECT wposts.ID AS ID,
wposts.post_title, wposts.post_status, wposts.post_name,
tag_terms.term_id AS tag_id
FROM `wp_posts` AS wposts
INNER JOIN wp_term_relationships AS tag_term_relationships ON (wposts.ID = tag_term_relationships.object_id)
INNER JOIN wp_term_taxonomy AS tag_term_taxonomy ON (tag_term_relationships.term_taxonomy_id = tag_term_taxonomy.term_taxonomy_id AND tag_term_taxonomy.taxonomy = 'post_tag')
INNER JOIN wp_terms AS tag_terms ON (tag_term_taxonomy.term_id = tag_terms.term_id)
WHERE wposts.ID = '12345'
AND wposts.post_type = 'post'
AND wposts.post_status NOT LIKE 'private'
AND tag_terms.term_id = '55'
GROUP BY wposts.ID
ORDER BY wposts.post_date ASC
これにより、タグIDが55のすべての投稿を照会する必要があります。
私が行う必要があるのは、この1つのタグだけが含まれているが、他のタグは含まれていないすべての投稿を除外することです。
タグがある場合は投稿を表示します23,34,55,67 しかし、タグ55(および他のタグはない)があれば投稿を表示したくありません。 この特定のタグを含まない投稿もクエリに含める必要があります。
どうすればよいですか?
...
GROUP BY wposts.ID
HAVING COUNT(tag_terms.term_id) <> 1
OR MAX(tag_terms.term_id) <> 55
ORDER BY wposts.post_date ASC
のみポストタイプとステータスを確認するためにあなたのWHERE
条件を変更:GROUP BY
とORDER BY
間HAVING
条件を追加する
あなたはそれが間違っています。 WP_queryクラスの投稿を常に選択する必要があります。http://codex.wordpress.org/Class_Reference/WP_Query – janw
独自のプラグインを開発している場合を除き、@janwに同意すると、SELECT文を書く必要はありません。 – twilson
ナンセンス。私はいくつかのメタ値、サムネイル、ユーザー名とタグをすべて同じクエリで照会する必要があります。 WP_Queryはダミーのためのもので、必要な柔軟性は許されません。 – reggie