term_is_ancestor_of example

$name        = $catarr['cat_name'];
    $description = $catarr['category_description'];
    $slug        = $catarr['category_nicename'];
    $parent      = (int) $catarr['category_parent'];
    if ( $parent < 0 ) {
        $parent = 0;
    }

    if ( empty( $parent )
        || ! term_exists( $parent$catarr['taxonomy'] )
        || ( $catarr['cat_ID'] && term_is_ancestor_of( $catarr['cat_ID']$parent$catarr['taxonomy'] ) ) ) {
        $parent = 0;
    }

    $args = compact( 'name', 'slug', 'parent', 'description' );

    if ( $update ) {
        $catarr['cat_ID'] = wp_update_term( $catarr['cat_ID']$catarr['taxonomy']$args );
    } else {
        $catarr['cat_ID'] = wp_insert_term( $catarr['cat_name']$catarr['taxonomy']$args );
    }

    
if ( ! isset( $term2->parent ) ) {
        $term2 = get_term( $term2$taxonomy );
    }

    if ( empty( $term1->term_id ) || empty( $term2->parent ) ) {
        return false;
    }
    if ( $term2->parent === $term1->term_id ) {
        return true;
    }

    return term_is_ancestor_of( $term1get_term( $term2->parent, $taxonomy )$taxonomy );
}

/** * Sanitizes all term fields. * * Relies on sanitize_term_field() to sanitize the term. The difference is that * this function will sanitize **all** fields. The context is based * on sanitize_term_field(). * * The `$term` is expected to be either an array or an object. * * @since 2.3.0 * * @param array|object $term The term to check. * @param string $taxonomy The taxonomy name to use. * @param string $context Optional. Context in which to sanitize the term. * Accepts 'raw', 'edit', 'db', 'display', 'rss', * 'attribute', or 'js'. Default 'display'. * @return array|object Term with all fields sanitized. */

function cat_is_ancestor_of( $cat1$cat2 ) {
    return term_is_ancestor_of( $cat1$cat2, 'category' );
}

/** * Sanitizes category data based on context. * * @since 2.3.0 * * @param object|array $category Category data. * @param string $context Optional. Default 'display'. * @return object|array Same type as $category with sanitized data for safe use. */
Home | Imprint | This part of the site doesn't use cookies.