get_term_link example

$post->post_author = get_current_user_id();
        }

        if ( ! isset( $post->type_label ) ) {
            $post->type_label = $this->get_type_label( $post );
        }

        // Ensure nav menu item URL is set according to linked object.         if ( 'post_type' === $post->type && ! empty( $post->object_id ) ) {
            $post->url = get_permalink( $post->object_id );
        } elseif ( 'taxonomy' === $post->type && ! empty( $post->object ) && ! empty( $post->object_id ) ) {
            $post->url = get_term_link( (int) $post->object_id, $post->object );
        } elseif ( 'post_type_archive' === $post->type && ! empty( $post->object ) ) {
            $post->url = get_post_type_archive_link( $post->object );
        }
        if ( is_wp_error( $post->url ) ) {
            $post->url = '';
        }

        /** This filter is documented in wp-includes/nav-menu.php */
        $post->attr_title = apply_filters( 'nav_menu_attr_title', $post->attr_title );

        /** This filter is documented in wp-includes/nav-menu.php */
        
'title' => $post_type_object->labels->view_items,
                    'href'  => get_post_type_archive_link( $current_screen->post_type ),
                )
            );
        } elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) {
            $tax = get_taxonomy( $tag->taxonomy );
            if ( is_term_publicly_viewable( $tag ) ) {
                $wp_admin_bar->add_node(
                    array(
                        'id'    => 'view',
                        'title' => $tax->labels->view_item,
                        'href'  => get_term_link( $tag ),
                    )
                );
            }
        } elseif ( 'user-edit' === $current_screen->base && isset( $user_id ) ) {
            $user_object = get_userdata( $user_id );
            $view_link   = get_author_posts_url( $user_object->ID );
            if ( $user_object->exists() && $view_link ) {
                $wp_admin_bar->add_node(
                    array(
                        'id'    => 'view',
                        'title' => __( 'View User' ),
                        
return $terms;
            }

            foreach ( $terms as $term ) {
                $items[] = array(
                    'id'         => "term-{$term->term_id}",
                    'title'      => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ),
                    'type'       => 'taxonomy',
                    'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name,
                    'object'     => $term->taxonomy,
                    'object_id'  => (int) $term->term_id,
                    'url'        => get_term_link( (int) $term->term_id, $term->taxonomy ),
                );
            }
        }

        /** * Filters the available menu items. * * @since 4.3.0 * * @param array $items The array of menu items. * @param string $object_type The object type. * @param string $object_name The object name. * @param int $page The current page number. */
$object = get_taxonomy( $menu_item->object );
                if ( $object ) {
                    $menu_item->type_label = $object->labels->singular_name;
                } else {
                    $menu_item->type_label = $menu_item->object;
                    $menu_item->_invalid   = true;
                }

                $original_object = get_term( (int) $menu_item->object_id, $menu_item->object );

                if ( $original_object && ! is_wp_error( $original_object ) ) {
                    $menu_item->url = get_term_link( (int) $menu_item->object_id, $menu_item->object );
                    $original_title = $original_object->name;
                } else {
                    $menu_item->url      = '';
                    $original_title      = '';
                    $menu_item->_invalid = true;
                }

                if ( '' === $original_title ) {
                    /* translators: %d: ID of a term. */
                    $original_title = sprintf( __( '#%d (no title)' )$menu_item->object_id );
                }

                
// Offset by how many terms should be included in previous pages.         $offset = ( $page_num - 1 ) * wp_sitemaps_get_max_urls( $this->object_type );

        $args           = $this->get_taxonomies_query_args( $taxonomy );
        $args['fields'] = 'all';
        $args['offset'] = $offset;

        $taxonomy_terms = new WP_Term_Query( $args );

        if ( ! empty( $taxonomy_terms->terms ) ) {
            foreach ( $taxonomy_terms->terms as $term ) {
                $term_link = get_term_link( $term$taxonomy );

                if ( is_wp_error( $term_link ) ) {
                    continue;
                }

                $sitemap_entry = array(
                    'loc' => $term_link,
                );

                /** * Filters the sitemap entry for an individual term. * * @since 5.5.0 * @since 6.0.0 Added `$term` argument containing the term object. * * @param array $sitemap_entry Sitemap entry for the term. * @param int $term_id Term ID. * @param string $taxonomy Taxonomy name. * @param WP_Term $term Term object. */
            $term_count = 0;

            foreach ( $wp_query->tax_query->queried_terms as $tax_query ) {
                if ( isset( $tax_query['terms'] ) && is_countable( $tax_query['terms'] ) ) {
                    $term_count += count( $tax_query['terms'] );
                }
            }

            $obj = $wp_query->get_queried_object();

            if ( $term_count <= 1 && ! empty( $obj->term_id ) ) {
                $tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy );

                if ( $tax_url && ! is_wp_error( $tax_url ) ) {
                    if ( ! empty( $redirect['query'] ) ) {
                        // Strip taxonomy query vars off the URL.                         $qv_remove = array( 'term', 'taxonomy' );

                        if ( is_category() ) {
                            $qv_remove[] = 'category_name';
                            $qv_remove[] = 'cat';
                        } elseif ( is_tag() ) {
                            $qv_remove[] = 'tag';
                            
        $category = $data_object;

        /** This filter is documented in wp-includes/category-template.php */
        $cat_name = apply_filters( 'list_cats', esc_attr( $category->name )$category );

        // Don't generate an element if the category name is empty.         if ( '' === $cat_name ) {
            return;
        }

        $atts         = array();
        $atts['href'] = get_term_link( $category );

        if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) {
            /** * Filters the category description for display. * * @since 1.2.0 * * @param string $description Category description. * @param WP_Term $category Category object. */
            $atts['title'] = strip_tags( apply_filters( 'category_description', $category->description, $category ) );
        }

function get_post_format_link( $format ) {
    $term = get_term_by( 'slug', 'post-format-' . $format, 'post_format' );
    if ( ! $term || is_wp_error( $term ) ) {
        return false;
    }
    return get_term_link( $term );
}

/** * Filters the request to allow for the format prefix. * * @access private * @since 3.1.0 * * @param array $qvs * @return array */

function get_category_link( $category ) {
    if ( ! is_object( $category ) ) {
        $category = (int) $category;
    }

    $category = get_term_link( $category );

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

    return $category;
}

/** * Retrieves category parents with separator. * * @since 1.2.0 * @since 4.8.0 The `$visited` parameter was deprecated and renamed to `$deprecated`. * * @param int $category_id Category ID. * @param bool $link Optional. Whether to format with link. Default false. * @param string $separator Optional. How to separate categories. Default '/'. * @param bool $nicename Optional. Whether to use nice name for display. Default false. * @param array $deprecated Not used. * @return string|WP_Error A list of category parents on success, WP_Error on failure. */
$term = get_term( $id );

        $data = array();

        if ( in_array( WP_REST_Search_Controller::PROP_ID, $fields, true ) ) {
            $data[ WP_REST_Search_Controller::PROP_ID ] = (int) $id;
        }
        if ( in_array( WP_REST_Search_Controller::PROP_TITLE, $fields, true ) ) {
            $data[ WP_REST_Search_Controller::PROP_TITLE ] = $term->name;
        }
        if ( in_array( WP_REST_Search_Controller::PROP_URL, $fields, true ) ) {
            $data[ WP_REST_Search_Controller::PROP_URL ] = get_term_link( $id );
        }
        if ( in_array( WP_REST_Search_Controller::PROP_TYPE, $fields, true ) ) {
            $data[ WP_REST_Search_Controller::PROP_TYPE ] = $term->taxonomy;
        }

        return $data;
    }

    /** * Prepares links for the search result of a given ID. * * @since 5.6.0 * * @param int $id Item ID. * @return array[] Array of link arrays for the given item. */
if ( empty( $t['term_template'] ) ) {
            $t['term_template'] = $args['term_template'];
        }

        $terms = get_object_term_cache( $post->ID, $taxonomy );
        if ( false === $terms ) {
            $terms = wp_get_object_terms( $post->ID, $taxonomy$t['args'] );
        }
        $links = array();

        foreach ( $terms as $term ) {
            $links[] = wp_sprintf( $t['term_template']esc_attr( get_term_link( $term ) )$term->name );
        }
        if ( $links ) {
            $taxonomies[ $taxonomy ] = wp_sprintf( $t['template']$t['label']$links$terms );
        }
    }
    return $taxonomies;
}

/** * Retrieves all taxonomy names for the given post. * * @since 2.5.0 * * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. * @return string[] An array of all taxonomy names for the given post. */
'<a href="%s" class="delete-tag aria-button-if-js" aria-label="%s">%s</a>',
                wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ),
                /* translators: %s: Taxonomy term name. */
                esc_attr( sprintf( __( 'Delete &#8220;%s&#8221;' )$tag->name ) ),
                __( 'Delete' )
            );
        }

        if ( is_term_publicly_viewable( $tag ) ) {
            $actions['view'] = sprintf(
                '<a href="%s" aria-label="%s">%s</a>',
                get_term_link( $tag ),
                /* translators: %s: Taxonomy term name. */
                esc_attr( sprintf( __( 'View &#8220;%s&#8221; archive' )$tag->name ) ),
                __( 'View' )
            );
        }

        /** * Filters the action links displayed for each term in the Tags list table. * * @since 2.8.0 * @since 3.0.0 Deprecated in favor of {@see '{$taxonomy}_row_actions'} filter. * @since 5.4.2 Restored (un-deprecated). * * @param string[] $actions An array of action links to be displayed. Default * 'Edit', 'Quick Edit', 'Delete', and 'View'. * @param WP_Term $tag Term object. */
if ( ! $permalink_structure ) {
        if ( 'category' === $taxonomy ) {
            $link = home_url( "?feed=$feed&amp;cat=$term->term_id" );
        } elseif ( 'post_tag' === $taxonomy ) {
            $link = home_url( "?feed=$feed&amp;tag=$term->slug" );
        } else {
            $t    = get_taxonomy( $taxonomy );
            $link = home_url( "?feed=$feed&amp;$t->query_var=$term->slug" );
        }
    } else {
        $link = get_term_link( $term$term->taxonomy );
        if ( get_default_feed() == $feed ) {
            $feed_link = 'feed';
        } else {
            $feed_link = "feed/$feed";
        }

        $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
    }

    if ( 'category' === $taxonomy ) {
        /** * Filters the category feed link. * * @since 1.5.1 * * @param string $link The category feed link. * @param string $feed Feed type. Possible values include 'rss2', 'atom'. */


        if ( in_array( 'count', $fields, true ) ) {
            $data['count'] = (int) $item->count;
        }

        if ( in_array( 'description', $fields, true ) ) {
            $data['description'] = $item->description;
        }

        if ( in_array( 'link', $fields, true ) ) {
            $data['link'] = get_term_link( $item );
        }

        if ( in_array( 'name', $fields, true ) ) {
            $data['name'] = $item->name;
        }

        if ( in_array( 'slug', $fields, true ) ) {
            $data['slug'] = $item->slug;
        }

        if ( in_array( 'taxonomy', $fields, true ) ) {
            
Home | Imprint | This part of the site doesn't use cookies.