get_ancestors example


    public function single_row( $tag$level = 0 ) {
        global $taxonomy;
        $tag = sanitize_term( $tag$taxonomy );

        $this->level = $level;

        if ( $tag->parent ) {
            $count = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
            $level = 'level-' . $count;
        } else {
            $level = 'level-0';
        }

        echo '<tr id="tag-' . $tag->term_id . '" class="' . $level . '">';
        $this->single_row_columns( $tag );
        echo '</tr>';
    }

    /** * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named parameter support. * * @param WP_Term $item Term object. * @return string */
'separator' => '/',
        'link'      => true,
        'inclusive' => true,
    );

    $args = wp_parse_args( $args$defaults );

    foreach ( array( 'link', 'inclusive' ) as $bool ) {
        $args[ $bool ] = wp_validate_boolean( $args[ $bool ] );
    }

    $parents = get_ancestors( $term_id$taxonomy, 'taxonomy' );

    if ( $args['inclusive'] ) {
        array_unshift( $parents$term_id );
    }

    foreach ( array_reverse( $parents ) as $term_id ) {
        $parent = get_term( $term_id$taxonomy );
        $name   = ( 'slug' === $args['format'] ) ? $parent->slug : $parent->name;

        if ( $args['link'] ) {
            $list .= '<a href="' . esc_url( get_term_link( $parent->term_id, $taxonomy ) ) . '">' . $name . '</a>' . $args['separator'];
        }
if ( 'category' === $taxonomy ) {
            $termlink = '?cat=' . $term->term_id;
        } elseif ( $t->query_var ) {
            $termlink = "?$t->query_var=$slug";
        } else {
            $termlink = "?taxonomy=$taxonomy&term=$slug";
        }
        $termlink = home_url( $termlink );
    } else {
        if ( ! empty( $t->rewrite['hierarchical'] ) ) {
            $hierarchical_slugs = array();
            $ancestors          = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' );
            foreach ( (array) $ancestors as $ancestor ) {
                $ancestor_term        = get_term( $ancestor$taxonomy );
                $hierarchical_slugs[] = $ancestor_term->slug;
            }
            $hierarchical_slugs   = array_reverse( $hierarchical_slugs );
            $hierarchical_slugs[] = $slug;
            $termlink             = str_replace( "%$taxonomy%", implode( '/', $hierarchical_slugs )$termlink );
        } else {
            $termlink = str_replace( "%$taxonomy%", $slug$termlink );
        }
        $termlink = home_url( user_trailingslashit( $termlink, 'category' ) );
    }

        );
        $x->send();
    }

    $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );

    $level     = 0;
    $noparents = '';

    if ( is_taxonomy_hierarchical( $taxonomy ) ) {
        $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
        ob_start();
        $wp_list_table->single_row( $tag$level );
        $noparents = ob_get_clean();
    }

    ob_start();
    $wp_list_table->single_row( $tag );
    $parents = ob_get_clean();

    require ABSPATH . 'wp-admin/includes/edit-tag-messages.php';

    
Home | Imprint | This part of the site doesn't use cookies.