WordPress.org

Make WordPress Core

Ticket #20903: 20903.diff

File 20903.diff, 808 bytes (added by westi, 3 years ago)

Simple fix using term_exits to check that the parent of a term exists before adding to the array to try again later.

  • wp-admin/includes/export.php

     
    9494 
    9595                // put categories in order with no child going before its parent 
    9696                while ( $cat = array_shift( $categories ) ) { 
    97                         if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) 
     97                        if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) { 
    9898                                $cats[$cat->term_id] = $cat; 
    99                         else 
     99                        } elseif ( term_exists( $cat->parent, 'category' ) ) { 
     100                                // Assume we will find the parent later 
    100101                                $categories[] = $cat; 
     102                        } else { 
     103                                // For some reason the parent is missing 
     104                                $cats[$cat->term_id] = $cat; 
     105                        } 
    101106                } 
    102107 
    103108                // put terms in order with no child going before its parent