WP 4.2.1 - Category - Taxonomy Selecting Fix
This is
WP core fix (temp)
If you have
WP 4.2.1 and have lots of category with 2-3 level child, you probably noticed dramatic drop down in speed - maybe even times out and dies - when you /or user try to list an ad and selecting categories. (category dropdown)
The issue is with
WP wp-includes/taxonomy.php
Here is temporary fix - (until
WP release it's fix)-
You will see an
incredible speed difference - in how categories select loads categories in steps of: parent/child/grand-child
Test it before - and test it after!
Open:
wp-includes/taxonomy.php
instruction:
//from = this is what you comment out
//change to// = this is the new line you add
around - line 3943
find section
// Include the term itself in the ancestors array, so we can properly detect when a loop has occurred.
if ( empty( $ancestors ) ) {
//from $ancestors[] = $term_id;
$ancestors[ $term_id ] = 1; //change to//
}
foreach ( (array) $terms as $term ) {
$use_id = false;
if ( !is_object($term) ) {
$term = get_term($term, $taxonomy);
if ( is_wp_error( $term ) )
return $term;
$use_id = true;
}
// Don't recurse if we've already identified the term as a child - this indicates a loop.
//from if ( in_array( $term->term_id, $ancestors ) ) {
if ( isset( $ancestors[ $term->term_id ] ) ) { //change to//
continue;
}
if ( $term->parent == $term_id ) {
if ( $use_id )
$term_list[] = $term->term_id;
else
$term_list[] = $term;
if ( !isset($has_children[$term->term_id]) )
continue;
//from if ( $use_id ) {
//from $ancestors = array_merge( $ancestors, $term_list );
//from } else {
//from $ancestors = array_merge( $ancestors, wp_list_pluck( $term_list, 'term_id' ) );
//from }
$ancestors[ $term->term_id ] = 1;; //change to//
if ( $children = _get_term_children( $term->term_id, $terms, $taxonomy, $ancestors) )
$term_list = array_merge($term_list, $children);
}
}