The get_callback
part is generated within the WP_REST_Controller::add_additional_fields_to_object()
method with:
$object[ $field_name ] = call_user_func(
$field_options['get_callback'],
$object,
$field_name,
$request,
$this->get_object_type()
);
That means the callback has four input arguments:
'get_callback' => function ( $object, $field_name, $request, $object_type ) {
// ...
}
and for the requested category object, we can get the term id with:
$term_id = $object['id'];
Related Posts:
- WP REST API: filter by category 1 AND category 2
- Why is per_page not working with categories in WP API?
- Select posts by name and category per REST API
- REST API: Display Category names in JSON?
- Add image to each podcast series (or category) in headless WordPress instance [closed]
- WP REST API not retrieving all categories
- Adding custom ID field to the categories
- Intermittent Gutenberg 504 Gateway Timeout when calling REST route to retrieve categories
- How to exit out of delete_categories and stop action?
- Pagination for custom categories template
- WooCommerce REST API not returning the default products category
- Get_term_meta() always returns false
- Taxonomy term RestApi data 10 rows limitions
- List all subcategories from category
- Get the children of the parent category
- How to remove the term “category” from category pagination?
- Force WordPress to Show Pages Instead of Category
- How do I get the category URL from get_the_category?
- Display all posts in category, with specific tag posts at top
- How to Set an Individual Homepage for Each User?
- Is there a way to remove categories in bulk?
- How to get dynamically custom post type that are under a certain category
- Is it possible to put next and previous category links?
- Custom category template pagination problem
- Getting category before saving post
- How do I change the sql query for wp_get_archive()
- Best way to programmatically link to multiple categories (union/intersection) [closed]
- WordPress Multisite – global categories
- How to get child categories of a given Post
- Display “add to cart” button on every listing in product category page?
- Code to pull in a PHP file named after the category ID
- How to filter posts by format and category via url?
- Woocommerce category show subcategories only/omit posts for specific category
- How to display widgets inside a page content without a plugin?
- shop page with all categories with paginate
- Category location styling
- Get Tags specific to Category using WooCommerce plugin
- Giving wp_list_categories the class of the category
- WordPress category page redirects in .htaccess not working
- Category archive rewrite rule to include category/subcategory?
- How can I automatically display a visual archive of subcategory posts [and thumbnails] separate from Parent category?
- The default code for “posts_nav_link” on category.php isn’t working
- How to organize custom categories for filtering and selecting
- Woocommerce custom category pages
- Custom sub taxonomy order by
- Hide uncategorized when no category set
- Have multiple category queries from the URL been fixed yet?
- Why is it so hard to show the URL of the current category and how to do it?
- Create menu locations for each category in wordpress
- How to get Next/previous_post_link to go through articles in top parent category
- Conditional loop for category
- How to make the ‘delete’ button inactive on some categories?
- Notice: Trying to get property of non-object in : custom fields category
- Array: What is this value based on?
- Thumbnail for categories / taxonomies plugin?
- Pagination for query_posts();
- echo get_post_meta of all post in a category to fill up a select field
- How to Link to Most Recent Custom Post of Same Term
- Category page not showing
- Notice: Undefined variable: category_id
- Change RSS format for specific categories
- I need to exclude from a query a category and a few custom taxonomies
- List post only under the category, exclude child category content
- Detect category choice for posts with multiple categories
- wp_insert_link not working
- Different size video display for category page (smaller) & detail page (larger)
- Adding tinymce to Custom Field boxes on Category edit page
- wp_list_categories : how do I sort by ID when IDs are not sequential
- Showing different posts on category pages
- add current-cat class to single post page
- How to exclude certain categories showing in Gutenberg?
- Problem with pagination block in Gutenberg
- How to redirect to category page if page does not exists?
- Sort categories by custom field in WordPress admin
- Remove “Category:” from Post meta
- Related to genre and category
- Get permalink to latest post in category
- How to load terms of a custom taxonomy of a product in woocommerce cart page
- restrict category to only logged in User
- Category and tag urls return 404 error
- Dynamically creating content on custom URL without getting 404
- Removin /page/2 from pagination
- get parent_category class in loop
- Display all of a post’s categories except the current category
- Alphabetize all but one category
- One category not displaying template updates
- How to display only category of blog without custom code?
- How to create a category or tag available exclusively to the admins and not to the users?
- Printing direct descendants of a category with WP_Query
- wordpress category.php query for featured news item, broken pagination and repeating posts
- Form Value of drop down category + Translation of ‘show option none’
- Echo class depending on Parent category
- Query pages by category
- List all authors by matching custom meta data on a category page
- Page view: Sorted by categories
- Anyway to hide a Category in the Categories section when adding/editing a post in WP Admin?
- How to display posts by author in a separate page, other than author.php?
- One color to category link depending on category ID
- Show subcategories and hide posts or show posts if not exists subcategories
- Restricted category in Woocommerce [closed]