rest_get_route_for_taxonomy_items example

$links['https://api.w.org/attachment'] = array(
                'href' => $attachments_url,
            );
        }

        $taxonomies = get_object_taxonomies( $post->post_type );

        if ( ! empty( $taxonomies ) ) {
            $links['https://api.w.org/term'] = array();

            foreach ( $taxonomies as $tax ) {
                $taxonomy_route = rest_get_route_for_taxonomy_items( $tax );

                // Skip taxonomies that are not public.                 if ( empty( $taxonomy_route ) ) {
                    continue;
                }
                $terms_url = add_query_arg(
                    'post',
                    $post->ID,
                    rest_url( $taxonomy_route )
                );

                

    protected function prepare_links( $taxonomy ) {
        return array(
            'collection'              => array(
                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
            ),
            'https://api.w.org/items' => array(
                'href' => rest_url( rest_get_route_for_taxonomy_items( $taxonomy->name ) ),
            ),
        );
    }

    /** * Retrieves the taxonomy's schema, conforming to JSON Schema. * * @since 4.7.0 * @since 5.0.0 The `visibility` property was added. * @since 5.9.0 The `rest_namespace` property was added. * * @return array Item schema data. */
// Store pagination values for headers.         $per_page = (int) $prepared_args['number'];
        $page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );

        $response->header( 'X-WP-Total', (int) $total_terms );

        $max_pages = ceil( $total_terms / $per_page );

        $response->header( 'X-WP-TotalPages', (int) $max_pages );

        $request_params = $request->get_query_params();
        $collection_url = rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) );
        $base           = add_query_arg( urlencode_deep( $request_params )$collection_url );

        if ( $page > 1 ) {
            $prev_page = $page - 1;

            if ( $prev_page > $max_pages ) {
                $prev_page = $max_pages;
            }

            $prev_link = add_query_arg( 'page', $prev_page$base );
            $response->link_header( 'prev', $prev_link );
        }

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 );

    /** * Filters the REST API route for a term. * * @since 5.5.0 * * @param string $route The route path. * @param WP_Term $term The term object. */
Home | Imprint | This part of the site doesn't use cookies.