WordPress.org

Forums

Term Management Tools
[resolved] Term Hierarchy Preservation (6 posts)

  1. callerc1
    Member
    Posted 1 year ago #

    Hi scribu,

    Im having a few issues when swapping terms to another taxonomy. The hierarchy of term gets lost and parent set to 0 in the " wp_term_taxonomy" table.

    Does this plugin support the hierarchy migration? I can confirm that the taxonomy I am swapping to has support hierarchical terms.

    Thanks in advance.

    Chris

    http://wordpress.org/plugins/term-management-tools/

  2. callerc1
    Member
    Posted 1 year ago #

    Hi scribu,

    After further debugging i believe there is a small bug in the handle_change_tax method. on line 173 of the term_management_tools.php

    array( 'parent' => 0 ),
    should be
    array( 'parent' => $term->parent ),

    essentially if the current term has a parent make sure we preserve it on tax change.

    Would be great to here you thoughts on this?

    Many Thanks

    Chris

  3. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    essentially if the current term has a parent make sure we preserve it on tax change.

    What if the parent term isn't also converted to the new taxonomy?

  4. callerc1
    Member
    Posted 1 year ago #

    Hi scribu,

    Good point. I agree if this was the case the parent should be reset. My fix doesn't work in this situation. I overlooked that.

    However i think its probably more than likely that if a user moves a child term they would move a parent at the same time. Which leads to the following user journey:

    User selects parent and its child terms and changes the tax to another that has hierarchical support. (Hierarchy is lost at convert on all children as they where selected along with the parent)

    I guess this is more more of a UX discussion now as it sounds like its handled this way by design.

    Would be great if the plugin could handle the above situation as well. ie check if parent term_id is in the term_ids array before reseting. something like this?:

    if ( $term->parent ) {
        if (!in_array($term->parent,$term_ids)) {
            $wpdb->update( $wpdb->term_taxonomy,
                array( 'parent' => 0 ),
                array( 'term_taxonomy_id' => $term->term_taxonomy_id )
            );
        }
    }

    Thanks

  5. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    That might work. Could you package it up as a pull request?

    Here's the repo: https://github.com/scribu/wp-term-management-tools

    If you don't know git, you can just edit the term-management-tools.php online and the github UI will guide you through the rest.

  6. callerc1
    Member
    Posted 1 year ago #

    All done.

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Term Management Tools
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.