Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shadyvb/bbedbc6917ccbbca35c908fe50a11010 to your computer and use it in GitHub Desktop.
Save shadyvb/bbedbc6917ccbbca35c908fe50a11010 to your computer and use it in GitHub Desktop.
SQL Query to remove uncategorised category from categorised articles
DELETE
FROM `{PREFIX}_term_relationships`
WHERE `term_taxonomy_id` = 1 AND `object_id` IN
( SELECT * FROM
(
SELECT object_id
FROM `{PREFIX}_term_relationships`
WHERE `term_taxonomy_id`
IN ( SELECT `term_taxonomy_id`
FROM `{PREFIX}_term_taxonomy`
WHERE `taxonomy` = 'category' )
GROUP BY `object_id`
HAVING ( COUNT( `object_id` ) > 1 )
)
AS X
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment