親カテゴリー「おやおや」とその子カテゴリー「こどもも」があるとします。WordPressでは子カテゴリー「こどもも」にチェックを入れた場合、親カテゴリー「おやおや」にはチェックが入りません。これを親カテゴリーにも自動的にチェックを入れるプラグイン(Parent Category Toggler)はあるのですが、これを過去分にさかのぼってチェックを入れるには?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO wp_term_relationships | |
SELECT object_id, term_taxonomy_id, 0 AS term_order | |
FROM ( | |
SELECT DISTINCT r.object_id, p.term_taxonomy_id | |
FROM wp_term_relationships AS r | |
INNER JOIN wp_term_taxonomy AS t ON r.term_taxonomy_id = t.term_taxonomy_id | |
INNER JOIN wp_term_taxonomy AS p ON t.parent = p.term_id | |
WHERE t.taxonomy = 'category' | |
AND t.parent > 0 ) AS a | |
WHERE NOT EXISTS | |
(SELECT 'x' | |
FROM wp_term_relationships AS b | |
WHERE a.object_id = b.object_id | |
AND a.term_taxonomy_id = b.term_taxonomy_id) | |
; |
コメントを残す