• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / wp_check_term_hierarchy_for_loops() – Checks the given subset of the term hierarchy for hierarchy loops.

You appear to be a bot. Output may be restricted

Description

Checks the given subset of the term hierarchy for hierarchy loops.

Prevents loops from forming and breaks those that it finds. Attached to the wp_update_term_parent filter.

Usage

$int = wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy );

Parameters

$parent
( int ) required – term_id of the parent for the term we're checking.
$term_id
( int ) required – The term we're checking.
$taxonomy
( string ) required – The taxonomy of the term we're checking.

Returns

int The new parent for the term.

Source

File name: wordpress/wp-includes/taxonomy.php
Lines:

1 to 29 of 29
function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) {
  // Nothing fancy here - bail.
  if ( ! $parent ) {
    return 0;
  }

  // Can't be its own parent.
  if ( $parent === $term_id ) {
    return 0;
  }

  // Now look for larger loops.
  $loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) );
  if ( ! $loop ) {
    return $parent; // No loop.
  }

  // Setting $parent to the given value causes a loop.
  if ( isset( $loop[ $term_id ] ) ) {
    return 0;
  }

  // There's a loop, but it doesn't contain $term_id. Break the loop.
  foreach ( array_keys( $loop ) as $loop_member ) {
    wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) );
  }

  return $parent;
}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 2nd April 2020

Primary Sidebar

Information

Function name: wp_check_term_hierarchy_for_loops
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/taxonomy.php
File ref: wp-includes/taxonomy.php
Deprecated?: No
API Letters: C,F,H,T,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites