You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Terms migration assignment fails when 2 differents post types #296
This is an exemple to enlight a missing behaviour or documentation improvement. I have posts with categories that I want to migrate to news with topics.
I do a wp cli post edit to migrate the post type from posts to news: for post_id in $(wp post list --post_type="post" --format=ids); do wp post update $post_id --post_type="news"; done;
I do a wp term migrate to migrate the terms from categories to topics: for term_id in $(wp term list category --format=ids); do wp term migrate $term_id --from=category --to=topic; done;
It results in not having anymore the news assigned to the topics 😢 Which is kind of normal since it would also require to change the relathionships.
What do you think about this?
Do you think it's a good idea to patch it or just add a warning in the documentation? or even both?
As when you want to reassign the terms to the same old posts, I was thinking to add a tag reassign={false|true}, which will check the relationship table. If the treated terms have an "old" relationship in the relationship table, then it preserve the post id in order to assign it to the fresh created term.
I was also wondering about changing the whole behaviour of the term migration, because for now, it is "copying" the terms into the destination taxonomy. It could be maybe easier for preserving metas and relationships, to just change the taxonomy for a term, as we do for the post type. What do you think?
The above does not really guarantee that the target taxonomy does even apply to the CPT you've migrated the posts to. That's also something that WP-CLI can't really change, as the CPT is registered via code.
I think we're missing a piece of the logic here, and I'm not entirely sure we can properly solve this reliably.
Should the reassignment logic check the taxonomy<=>CPT relationship and throw an error if incorrect?
You are totally right on one thing, it's not required that the taxonomy belongs to both CPT or the reverse.
Anyhow, we could check that and throw an error.
But that could lead to another issue, it means that the taxonomy should be edited to belong to two CPT, do the export, then fix it forever only with the new CPT? It looks like it's not handy :/
changed the title [-]Terms migration assignation fails when 2 differents post types[/-][+]Terms migration assignment fails when 2 differents post types[/+]on Feb 2, 2026
Activity
schlessera commentedon Jun 29, 2020
Yes, I think this should be a supported use case, probably using an additional flag or two.
Do you have a plan of attack for this already?
MaximeCulea commentedon Jun 29, 2020
As when you want to reassign the terms to the same old posts, I was thinking to add a tag
reassign={false|true}, which will check the relationship table. If the treated terms have an "old" relationship in the relationship table, then it preserve the post id in order to assign it to the fresh created term.I was also wondering about changing the whole behaviour of the term migration, because for now, it is "copying" the terms into the destination taxonomy. It could be maybe easier for preserving metas and relationships, to just change the taxonomy for a term, as we do for the post type. What do you think?
schlessera commentedon Jul 22, 2020
The above does not really guarantee that the target taxonomy does even apply to the CPT you've migrated the posts to. That's also something that WP-CLI can't really change, as the CPT is registered via code.
I think we're missing a piece of the logic here, and I'm not entirely sure we can properly solve this reliably.
Should the reassignment logic check the taxonomy<=>CPT relationship and throw an error if incorrect?
MaximeCulea commentedon Nov 8, 2020
You are totally right on one thing, it's not required that the taxonomy belongs to both CPT or the reverse.
Anyhow, we could check that and throw an error.
But that could lead to another issue, it means that the taxonomy should be edited to belong to two CPT, do the export, then fix it forever only with the new CPT? It looks like it's not handy :/
[-]Terms migration assignation fails when 2 differents post types[/-][+]Terms migration assignment fails when 2 differents post types[/+]