Skip to content

Instantly share code, notes, and snippets.

@haze83
Last active March 16, 2026 18:08
Show Gist options
  • Select an option

  • Save haze83/f5608089509d09ce11340da97d8d883a to your computer and use it in GitHub Desktop.

Select an option

Save haze83/f5608089509d09ce11340da97d8d883a to your computer and use it in GitHub Desktop.
F4 Skuld
/* select skuld_cont_inst with wrong language */
SELECT p.ID ci_id,
p.post_parent ci_parent,
p.post_type ci_post_type,
tt.term_taxonomy_id ci_tt_id,
t.slug ci_lang,
p_p.*
FROM wp_posts AS p
INNER JOIN wp_term_relationships AS tr
ON tr.object_id = p.ID
INNER JOIN wp_term_taxonomy AS tt
ON tt.term_taxonomy_id = tr.term_taxonomy_id
AND tt.taxonomy = 'language'
INNER JOIN wp_terms AS t
ON t.term_id = tt.term_id
INNER JOIN (
SELECT
pp.ID p_id,
pp.post_parent p_parent,
pp.post_type p_post_type,
ptt.term_taxonomy_id p_tt_id,
pt.slug p_lang
FROM wp_posts AS pp
INNER JOIN wp_term_relationships AS ptr
ON ptr.object_id = pp.ID
INNER JOIN wp_term_taxonomy AS ptt
ON ptt.term_taxonomy_id = ptr.term_taxonomy_id
AND ptt.taxonomy = 'language'
INNER JOIN wp_terms AS pt
ON pt.term_id = ptt.term_id
) AS p_p ON p.post_parent = p_p.p_id
WHERE p.post_type = 'skuld_cont_inst'
AND t.slug <> p_p.p_lang
;
/* update skuld_cont_inst with correct language from parent */
UPDATE wp_term_relationships
INNER JOIN (
SELECT p.ID ci_id,
p.post_parent ci_parent,
p.post_type ci_post_type,
tt.term_taxonomy_id ci_tt_id,
t.slug ci_lang,
p_p.p_tt_id
FROM wp_posts AS p
INNER JOIN wp_term_relationships AS tr
ON tr.object_id = p.ID
INNER JOIN wp_term_taxonomy AS tt
ON tt.term_taxonomy_id = tr.term_taxonomy_id
AND tt.taxonomy = 'language'
INNER JOIN wp_terms AS t
ON t.term_id = tt.term_id
INNER JOIN (
SELECT
pp.ID p_id,
pp.post_parent p_parent,
pp.post_type p_post_type,
ptt.term_taxonomy_id p_tt_id,
pt.slug p_lang
FROM wp_posts AS pp
INNER JOIN wp_term_relationships AS ptr
ON ptr.object_id = pp.ID
INNER JOIN wp_term_taxonomy AS ptt
ON ptt.term_taxonomy_id = ptr.term_taxonomy_id
AND ptt.taxonomy = 'language'
INNER JOIN wp_terms AS pt
ON pt.term_id = ptt.term_id
) AS p_p ON p.post_parent = p_p.p_id
WHERE p.post_type = 'skuld_cont_inst'
AND t.slug <> p_p.p_lang
) AS sub_select
ON wp_term_relationships.object_id = sub_select.ci_id AND wp_term_relationships.term_taxonomy_id = sub_select.ci_tt_id
SET term_taxonomy_id = sub_select.p_tt_id
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment