get_term example

protected function check_assign_terms_permission( $request ) {
        $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
        foreach ( $taxonomies as $taxonomy ) {
            $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;

            if ( ! isset( $request[ $base ] ) ) {
                continue;
            }

            foreach ( (array) $request[ $base ] as $term_id ) {
                // Invalid terms will be rejected later.                 if ( ! get_term( $term_id$taxonomy->name ) ) {
                    continue;
                }

                if ( ! current_user_can( 'assign_term', (int) $term_id ) ) {
                    return false;
                }
            }
        }

        return true;
    }

    
// Grab a snapshot of post IDs, just in case it changes during the export.     $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where);

    /* * Get the requested terms ready, empty unless posts filtered by category * or all content. */
    $cats  = array();
    $tags  = array();
    $terms = array();
    if ( isset( $term ) && $term ) {
        $cat  = get_term( $term['term_id'], 'category' );
        $cats = array( $cat->term_id => $cat );
        unset( $term$cat );
    } elseif ( 'all' === $args['content'] ) {
        $categories = (array) get_categories( array( 'get' => 'all' ) );
        $tags       = (array) get_tags( array( 'get' => 'all' ) );

        $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
        $custom_terms      = (array) get_terms(
            array(
                'taxonomy' => $custom_taxonomies,
                'get'      => 'all',
            )
/** * Retrieves category name based on category ID. * * @since 0.71 * * @param int $cat_id Category ID. * @return string|WP_Error Category name on success, WP_Error on failure. */
function get_the_category_by_ID( $cat_id ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid     $cat_id   = (int) $cat_id;
    $category = get_term( $cat_id );

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

    return ( $category ) ? $category->name : '';
}

/** * Retrieves category list for a post in either HTML list or custom format. * * Generally used for quick, delimited (e.g. comma-separated) lists of categories, * as part of a post entry meta. * * For a more powerful, list-based function, see wp_list_categories(). * * @since 1.5.1 * * @see wp_list_categories() * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $separator Optional. Separator between the categories. By default, the links are placed * in an unordered list. An empty string will result in the default behavior. * @param string $parents Optional. How to display the parents. Accepts 'multiple', 'single', or empty. * Default empty string. * @param int $post_id Optional. ID of the post to retrieve categories for. Defaults to the current post. * @return string Category list for a post. */

    public function column_categories( $link ) {
        global $cat_id;

        $cat_names = array();
        foreach ( $link->link_category as $category ) {
            $cat = get_term( $category, 'link_category', OBJECT, 'display' );
            if ( is_wp_error( $cat ) ) {
                echo $cat->get_error_message();
            }
            $cat_name = $cat->name;
            if ( (int) $cat_id !== $category ) {
                $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
            }
            $cat_names[] = $cat_name;
        }
        echo implode( ', ', $cat_names );
    }

    

function get_category( $category$output = OBJECT, $filter = 'raw' ) {
    $category = get_term( $category, 'category', $output$filter );

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

    _make_cat_compat( $category );

    return $category;
}

/** * Retrieves a category based on URL containing the category slug. * * Breaks the $category_path parameter up to get the category slug. * * Tries to find the child path and will return it. If it doesn't find a * match, then it will return the first category matching slug, if $full_match, * is set to false. If it does not, then it will return null. * * It is also possible that it will return a WP_Error object on failure. Check * for it when using this function. * * @since 2.1.0 * * @param string $category_path URL containing category slugs. * @param bool $full_match Optional. Whether full path should be matched. * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which * correspond to a WP_Term object, an associative array, or a numeric array, * respectively. Default OBJECT. * @return WP_Term|array|WP_Error|null Type is based on $output value. */
if ( $term->parent !== $parent_term && empty( $_REQUEST['s'] ) ) {
                continue;
            }

            // If the page starts in a subtree, print the parents.             if ( $count === $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
                $my_parents = array();
                $parent_ids = array();
                $p          = $term->parent;

                while ( $p ) {
                    $my_parent    = get_term( $p$taxonomy );
                    $my_parents[] = $my_parent;
                    $p            = $my_parent->parent;

                    if ( in_array( $p$parent_ids, true ) ) { // Prevent parent loops.                         break;
                    }

                    $parent_ids[] = $p;
                }

                unset( $parent_ids );

                
/** * Filters the category that gets used in the %category% permalink token. * * @since 3.5.0 * * @param WP_Term $cat The category to use in the permalink. * @param array $cats Array of all categories (WP_Term objects) associated with the post. * @param WP_Post $post The post in question. */
                $category_object = apply_filters( 'post_link_category', $cats[0]$cats$post );

                $category_object = get_term( $category_object, 'category' );
                $category        = $category_object->slug;
                if ( $category_object->parent ) {
                    $category = get_category_parents( $category_object->parent, false, '/', true ) . $category;
                }
            }
            /* * Show default category in permalinks, * without having to assign it explicitly. */
            if ( empty( $category ) ) {
                $default_category = get_term( get_option( 'default_category' ), 'category' );
                
_doing_it_wrong(
                    __FUNCTION__,
                    sprintf( $message, '<code>' . $cap . '</code>' ),
                    '6.1.0'
                );

                $caps[] = 'do_not_allow';
                break;
            }

            $term_id = (int) $args[0];
            $term    = get_term( $term_id );
            if ( ! $term || is_wp_error( $term ) ) {
                $caps[] = 'do_not_allow';
                break;
            }

            $tax = get_taxonomy( $term->taxonomy );
            if ( ! $tax ) {
                $caps[] = 'do_not_allow';
                break;
            }

            
/** * Gets the REST API route for a term. * * @since 5.5.0 * * @param int|WP_Term $term Term ID or term object. * @return string The route path with a leading slash for the given term, * or an empty string if there is not a route. */
function rest_get_route_for_term( $term ) {
    $term = get_term( $term );

    if ( ! $term instanceof WP_Term ) {
        return '';
    }

    $taxonomy_route = rest_get_route_for_taxonomy_items( $term->taxonomy );
    if ( ! $taxonomy_route ) {
        return '';
    }

    $route = sprintf( '%s/%d', $taxonomy_route$term->term_id );

    
$term_data['name'] = trim( $content_struct['name'] );
        if ( empty( $term_data['name'] ) ) {
            return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
        }

        if ( isset( $content_struct['parent'] ) ) {
            if ( ! $taxonomy['hierarchical'] ) {
                return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) );
            }

            $parent_term_id = (int) $content_struct['parent'];
            $parent_term    = get_term( $parent_term_id$taxonomy['name'] );

            if ( is_wp_error( $parent_term ) ) {
                return new IXR_Error( 500, $parent_term->get_error_message() );
            }

            if ( ! $parent_term ) {
                return new IXR_Error( 403, __( 'Parent term does not exist.' ) );
            }

            $term_data['parent'] = $content_struct['parent'];
        }

        

                    );
                    echo "\n";
                }
            }
        } elseif ( taxonomy_exists( $object_type ) ) {
            if ( isset( $request['ID'] ) ) {
                $object_id = (int) $request['ID'];

                if ( 'markup' === $response_format ) {
                    echo walk_nav_menu_tree(
                        array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id$object_type ) ) ),
                        0,
                        (object) $args
                    );
                } elseif ( 'json' === $response_format ) {
                    $post_obj = get_term( $object_id$object_type );
                    echo wp_json_encode(
                        array(
                            'ID'         => $object_id,
                            'post_title' => $post_obj->name,
                            'post_type'  => $object_type,
                        )
                    );
switch ( $object_type ) {
        case 'post':
            $post_type = get_post_type( $object_id );

            if ( ! empty( $post_type ) ) {
                $object_subtype = $post_type;
            }
            break;

        case 'term':
            $term = get_term( $object_id );
            if ( ! $term instanceof WP_Term ) {
                break;
            }

            $object_subtype = $term->taxonomy;
            break;

        case 'comment':
            $comment = get_comment( $object_id );
            if ( ! $comment ) {
                break;
            }
$link          = str_replace( '<a', '<a aria-current="page"', $link );
                    } elseif ( $category->term_id === $_current_term->parent ) {
                        $css_classes[] = 'current-cat-parent';
                    }

                    while ( $_current_term->parent ) {
                        if ( $category->term_id === $_current_term->parent ) {
                            $css_classes[] = 'current-cat-ancestor';
                            break;
                        }

                        $_current_term = get_term( $_current_term->parent, $category->taxonomy );
                    }
                }
            }

            /** * Filters the list of CSS classes to include with each category in the list. * * @since 4.2.0 * * @see wp_list_categories() * * @param string[] $css_classes An array of CSS classes to be applied to each list item. * @param WP_Term $category Category data object. * @param int $depth Depth of page, used for padding. * @param array $args An array of wp_list_categories() arguments. */


        $this->queried_object    = null;
        $this->queried_object_id = null;

        if ( $this->is_category || $this->is_tag || $this->is_tax ) {
            if ( $this->is_category ) {
                $cat           = $this->get( 'cat' );
                $category_name = $this->get( 'category_name' );

                if ( $cat ) {
                    $term = get_term( $cat, 'category' );
                } elseif ( $category_name ) {
                    $term = get_term_by( 'slug', $category_name, 'category' );
                }
            } elseif ( $this->is_tag ) {
                $tag_id = $this->get( 'tag_id' );
                $tag    = $this->get( 'tag' );

                if ( $tag_id ) {
                    $term = get_term( $tag_id, 'post_tag' );
                } elseif ( $tag ) {
                    $term = get_term_by( 'slug', $tag, 'post_tag' );
                }
// No need to perform a query for empty 'slug' or 'name'.     if ( 'slug' === $field || 'name' === $field ) {
        $value = (string) $value;

        if ( 0 === strlen( $value ) ) {
            return false;
        }
    }

    if ( 'id' === $field || 'ID' === $field || 'term_id' === $field ) {
        $term = get_term( (int) $value$taxonomy$output$filter );
        if ( is_wp_error( $term ) || null === $term ) {
            $term = false;
        }
        return $term;
    }

    $args = array(
        'get'                    => 'all',
        'number'                 => 1,
        'taxonomy'               => $taxonomy,
        'update_term_meta_cache' => false,
        
Home | Imprint | This part of the site doesn't use cookies.