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
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- How To Find Out WordPress Category Table in MYSQL?
- Add custom field to Category
- Different template for subcategories
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- How to get this only in small letters (lowercase)? [closed]
- How to totally get rid of Category in my blog?
- Is there a function to cause empty categories not to show in menus?
- Disable pagination only for specific category
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Category Specific Archive
- How to add categories to products in woocommerce programatically? [closed]
- Is there a plugin that will completely remove the category system?
- How to get the number of child categories a specific parent category has?
- Removing category base form links messes up the parent-child behavior
- display woocommerce all category title on home page
- When to use ‘get_category_by_path’ vs. ‘get_term_by’ to get category object from `get_query_var( ‘category_name’ )`?
- One WP install, I need to map a custom domain name to each category
- Show thumbnail for category?
- get_the_category_list() does not give me all my categories
- How to disable category without deleting?
- How to get category name from URL and pass to a template
- Displaying multiple loops based off of category
- Display Categories, Sub-categories, and Sub-sub-categories on separate pages
- WooCommerce IF statements not working
- Limit number of terms that a custom taxonomy can save per custom post type
- Category pie diagram meta box in post editing page
- There any way to get de percentage of number of post by user and category?
- query cat orderby and order not working
- How to display categories which contains particular tag?
- Add tag parameter to category.php
- Why custom taxomony not showing when create a post?
- Single.php Category Post Count
- wp_list_categories with show_count, except for specific categories
- Show the amount of posts in a tag in a specific category has
- Adding a H1 Tag to Post Tags automatically, but hide the tag? (Same for Category)
- List recent posts with link to first category
- How do I add a category to my post_type
- Link from navbar to categories
- WordPress showing wrong category name
- Add posts of a certain category to a page
- Show 10 Sub Categories Per Parent Category Page?
- Conditional category & tag statement
- How can I filter posts by tag on the fly
- Post Loop Category first show parent then child
- How to display posts from specific category using get_option function?
- wp_nav_menu not appearing correctly on category page
- Post not found when filtered by category ID
- How to detect /category and /tag base pages?
- How to Show or Hidden Categories on page in WordPress?
- Display all posts from selected category
- Is there any better/faster code than this ? It shows the categories that an author had ever posted in
- category description not showing in my woocommerce
- Hide Some Categories in Post Editor
- in post content shortcode works, but hardcoded in same page template doesn’t?
- Only 10 of 233 categories selectable when adding a new post
- When creating category, it creates automatically tag, or, when creating tag, it creates automatically category in same name
- Should I select only the last child product category?
- List posts from a category and embed them into a page
- Media Library Categories
- Exclude category from WP_Query args not working
- WordPress pagination based on category
- How to echo Tags and Categories as plain text
- Get category of a taxonomy for a queries object in a loop
- Make related posts display first in search result
- Display sub categories of a parent product in products – woocommerce [closed]
- Loop within category’s posts
- WordPress edit.php category filter to show only posts from direct category and not posts from it child category
- How can I just show portfolio items from 1 category on portfolio page?
- Children categories not shown in dashboard
- Loops in category description
- Detecting top parent category fails on home page
- Link categories to last post
- wp_list_categories not working on my live site
- Indenting Category list
- Remove Comments section from certain category posts
- add an image field to wordpress category
- How to display a linked category name with get_the_category
- Not able to display category link and name [closed]
- How to display category list with category description
- how do i set an image for a category in admin panel
- Issue on Listing Sub Product Categories In Woocommerce
- How to retrieve posts from parent category, splitting them per children when displayed?
- Display Product category in archive product page
- Categories and products woocommerce wordpress
- Invalid login email notification for password-protected category