WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Term Hierarchy Preservation

[Resolved] Term Hierarchy Preservation

  • 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/

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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

    Plugin Author scribu
    Member

    @scribu

    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?

    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

    Plugin Author scribu
    Member

    @scribu

    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.

    All done.

    Cheers

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Term Hierarchy Preservation’ is closed to new replies.