WP_Term example



    if ( $taxonomy && ! taxonomy_exists( $taxonomy ) ) {
        return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
    }

    if ( $term instanceof WP_Term ) {
        $_term = $term;
    } elseif ( is_object( $term ) ) {
        if ( empty( $term->filter ) || 'raw' === $term->filter ) {
            $_term = sanitize_term( $term$taxonomy, 'raw' );
            $_term = new WP_Term( $_term );
        } else {
            $_term = WP_Term::get_instance( $term->term_id );
        }
    } else {
        $_term = WP_Term::get_instance( $term$taxonomy );
    }

    if ( is_wp_error( $_term ) ) {
        return $_term;
    } elseif ( ! $_term ) {
        return null;
    }
return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
            }

            $_term = sanitize_term( $_term$_term->taxonomy, 'raw' );

            // Don't cache terms that are shared between taxonomies.             if ( 1 === count( $terms ) ) {
                wp_cache_add( $term_id$_term, 'terms' );
            }
        }

        $term_obj = new WP_Term( $_term );
        $term_obj->filter( $term_obj->filter );

        return $term_obj;
    }

    /** * Constructor. * * @since 4.4.0 * * @param WP_Term|object $term Term object. */
Home | Imprint | This part of the site doesn't use cookies.