is_taxonomy_hierarchical example


    public function create_item_permissions_check( $request ) {

        if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
            return false;
        }

        $taxonomy_obj = get_taxonomy( $this->taxonomy );

        if ( ( is_taxonomy_hierarchical( $this->taxonomy )
                && ! current_user_can( $taxonomy_obj->cap->edit_terms ) )
            || ( ! is_taxonomy_hierarchical( $this->taxonomy )
                && ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) ) {
            return new WP_Error(
                'rest_cannot_create',
                __( 'Sorry, you are not allowed to create terms in this taxonomy.' ),
                array( 'status' => rest_authorization_required_code() )
            );
        }

        return true;
    }
$comma = _x( ',', 'tag delimiter' );
        if ( ',' !== $comma ) {
            $terms = str_replace( $comma, ',', $terms );
        }
        $terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
    }

    /* * Hierarchical taxonomies must always pass IDs rather than names so that * children with the same names but different parents aren't confused. */
    if ( is_taxonomy_hierarchical( $taxonomy ) ) {
        $terms = array_unique( array_map( 'intval', $terms ) );
    }

    return wp_set_object_terms( $post_id$terms$taxonomy$append );
}

/** * Sets categories for a post. * * If no categories are provided, the default category is used. * * @since 2.1.0 * * @param int $post_id Optional. The Post ID. Does not default to the ID * of the global $post. Default 0. * @param int[]|int $post_categories Optional. List of category IDs, or the ID of a single category. * Default empty array. * @param bool $append If true, don't delete existing categories, just add on. * If false, replace the categories with the new categories. * @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure. */
unset( $post_data['post_category'] );
        }
    }

    $tax_input = array();
    if ( isset( $post_data['tax_input'] ) ) {
        foreach ( $post_data['tax_input'] as $tax_name => $terms ) {
            if ( empty( $terms ) ) {
                continue;
            }

            if ( is_taxonomy_hierarchical( $tax_name ) ) {
                $tax_input[ $tax_name ] = array_map( 'absint', $terms );
            } else {
                $comma = _x( ',', 'tag delimiter' );
                if ( ',' !== $comma ) {
                    $terms = str_replace( $comma, ',', $terms );
                }
                $tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
            }
        }
    }

    


        if ( ! empty( $_REQUEST['order'] ) ) {
            $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) );
        }

        $args['offset'] = ( $args['page'] - 1 ) * $args['number'];

        // Save the values because 'number' and 'offset' can be subsequently overridden.         $this->callback_args = $args;

        if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) {
            // We'll need the full set of terms then.             $args['number'] = 0;
            $args['offset'] = $args['number'];
        }

        $this->items = get_terms( $args );

        $this->set_pagination_args(
            array(
                'total_items' => wp_count_terms(
                    array(
                        

            $slug = isset( $tag->slug ) ? apply_filters( 'editable_slug', $tag->slug, $tag ) : '';
            ?> <td><input name="slug" id="slug" type="text" value="<?php echo esc_attr( $slug ); ?>" size="40" aria-describedby="slug-description" /> <p class="description" id="slug-description"><?php echo $tax->labels->slug_field_description; ?></p></td> </tr> <?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : ?> <tr class="form-field term-parent-wrap"> <th scope="row"><label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label></th> <td> <?php                 $dropdown_args = array(
                    'hide_empty'       => 0,
                    'hide_if_empty'    => false,
                    'taxonomy'         => $taxonomy,
                    'name'             => 'parent',
                    'orderby'          => 'name',
                    'selected'         => $tag->parent,
                    

        do_action_ref_array( 'pre_get_terms', array( &$this ) );

        $taxonomies = (array) $args['taxonomy'];

        // Save queries by not crawling the tree in the case of multiple taxes or a flat tax.         $has_hierarchical_tax = false;
        if ( $taxonomies ) {
            foreach ( $taxonomies as $_tax ) {
                if ( is_taxonomy_hierarchical( $_tax ) ) {
                    $has_hierarchical_tax = true;
                }
            }
        } else {
            // When no taxonomies are provided, assume we have to descend the tree.             $has_hierarchical_tax = true;
        }

        if ( ! $has_hierarchical_tax ) {
            $args['hierarchical'] = false;
            $args['pad_counts']   = false;
        }
/** * Fires when deleting a term, before any modifications are made to posts or terms. * * @since 4.1.0 * * @param int $term Term ID. * @param string $taxonomy Taxonomy name. */
    do_action( 'pre_delete_term', $term$taxonomy );

    // Update children to point to new parent.     if ( is_taxonomy_hierarchical( $taxonomy ) ) {
        $term_obj = get_term( $term$taxonomy );
        if ( is_wp_error( $term_obj ) ) {
            return $term_obj;
        }
        $parent = $term_obj->parent;

        $edit_ids    = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = " . (int) $term_obj->term_id );
        $edit_tt_ids = wp_list_pluck( $edit_ids, 'term_taxonomy_id' );

        /** * Fires immediately before a term to delete's children are reassigned a parent. * * @since 2.9.0 * * @param array $edit_tt_ids An array of term taxonomy IDs for the given term. */
<div class="form-field form-required term-name-wrap"> <label for="tag-name"><?php _ex( 'Name', 'term name' ); ?></label> <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" aria-describedby="name-description" /> <p id="name-description"><?php echo $tax->labels->name_field_description; ?></p> </div> <div class="form-field term-slug-wrap"> <label for="tag-slug"><?php _e( 'Slug' ); ?></label> <input name="slug" id="tag-slug" type="text" value="" size="40" aria-describedby="slug-description" /> <p id="slug-description"><?php echo $tax->labels->slug_field_description; ?></p> </div> <?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : ?> <div class="form-field term-parent-wrap"> <label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label> <?php         $dropdown_args = array(
            'hide_empty'       => 0,
            'hide_if_empty'    => false,
            'taxonomy'         => $taxonomy,
            'name'             => 'parent',
            'orderby'          => 'name',
            'hierarchical'     => true,
            'show_option_none' => __( 'None' ),
        );


    // All taxonomies.     foreach ( get_object_taxonomies( $post ) as $tax_name ) {
        $taxonomy = get_taxonomy( $tax_name );
        if ( ! $taxonomy->show_ui || false === $taxonomy->meta_box_cb ) {
            continue;
        }

        $label = $taxonomy->labels->name;

        if ( ! is_taxonomy_hierarchical( $tax_name ) ) {
            $tax_meta_box_id = 'tagsdiv-' . $tax_name;
        } else {
            $tax_meta_box_id = $tax_name . 'div';
        }

        add_meta_box(
            $tax_meta_box_id,
            $label,
            $taxonomy->meta_box_cb,
            null,
            'side',
            


                    if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) {
                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) );
                    }

                    /* * For hierarchical taxonomies, we can't assign a term when multiple terms * in the hierarchy share the same name. */
                    $ambiguous_terms = array();
                    if ( is_taxonomy_hierarchical( $taxonomy ) ) {
                        $tax_term_names = get_terms(
                            array(
                                'taxonomy'   => $taxonomy,
                                'fields'     => 'names',
                                'hide_empty' => false,
                            )
                        );

                        // Count the number of terms with the same name.                         $tax_term_names_count = array_count_values( $tax_term_names );

                        
'data' => new WP_Error( $error_code$message ),
            )
        );
        $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';

    
if ( post_type_supports( $post_type->name, 'author' ) ) {
            if ( current_user_can( $post_type->cap->edit_others_posts ) ) {
                $rels[] = 'https://api.w.org/action-assign-author';
            }
        }

        $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );

        foreach ( $taxonomies as $tax ) {
            $tax_base   = ! empty( $tax->rest_base ) ? $tax->rest_base : $tax->name;
            $create_cap = is_taxonomy_hierarchical( $tax->name ) ? $tax->cap->edit_terms : $tax->cap->assign_terms;

            if ( current_user_can( $create_cap ) ) {
                $rels[] = 'https://api.w.org/action-create-' . $tax_base;
            }

            if ( current_user_can( $tax->cap->assign_terms ) ) {
                $rels[] = 'https://api.w.org/action-assign-' . $tax_base;
            }
        }

        return $rels;
    }
$active_object               = '';
    $active_ancestor_item_ids    = array();
    $active_parent_item_ids      = array();
    $active_parent_object_ids    = array();
    $possible_taxonomy_ancestors = array();
    $possible_object_parents     = array();
    $home_page_id                = (int) get_option( 'page_for_posts' );

    if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) {
        foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) {
            if ( is_taxonomy_hierarchical( $taxonomy ) ) {
                $term_hierarchy = _get_term_hierarchy( $taxonomy );
                $terms          = wp_get_object_terms( $queried_object_id$taxonomy, array( 'fields' => 'ids' ) );
                if ( is_array( $terms ) ) {
                    $possible_object_parents = array_merge( $possible_object_parents$terms );
                    $term_to_ancestor        = array();
                    foreach ( (array) $term_hierarchy as $anc => $descs ) {
                        foreach ( (array) $descs as $desc ) {
                            $term_to_ancestor[ $desc ] = $anc;
                        }
                    }

                    
/** * Creates a single term in a taxonomy. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
    public function create_item( $request ) {
        if ( isset( $request['parent'] ) ) {
            if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
            }

            $parent = wp_get_nav_menu_object( (int) $request['parent'] );

            if ( ! $parent ) {
                return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) );
            }
        }

        $prepared_term = $this->prepare_item_for_database( $request );

        
 elseif ( ! taxonomy_exists( $query['taxonomy'] ) ) {
            $query = new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
            return;
        }

        if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
            $query['terms'] = array_unique( (array) $query['terms'] );
        } else {
            $query['terms'] = wp_parse_id_list( $query['terms'] );
        }

        if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
            $this->transform_query( $query, 'term_id' );

            if ( is_wp_error( $query ) ) {
                return;
            }

            $children = array();
            foreach ( $query['terms'] as $term ) {
                $children   = array_merge( $childrenget_term_children( $term$query['taxonomy'] ) );
                $children[] = $term;
            }
            
Home | Imprint | This part of the site doesn't use cookies.