The code in your question uses the old admin AJAX API, and while I would normally advise you switch to the REST API, or fix the AJAX you already have, neither are necessary.
WordPress already provides an endpoint that contains the post count and other information!
https://<yoursite>/wp-json/wp/v2/categories/<category ID>
E.g. on my own site the category with ID 5 can be requested from the REST API at /wp-json/wp/v2/categories/5 and WordPress responds with JSON data:
{"id":5,"count":6,"description":"",...etc
The information includes parent terms, URLs, metadata etc
You can also get a general list of all categories by visiting /wp-json/wp/v2/categories/ without a term ID, and you can also pass additional parameters to filter and constrain the results.
Similar endpoints exist for tags and posts, e.g. /wp/v2/posts
Related Posts:
- How to filter post data with AJAX on page?
- Ajax filter with custom taxonomies
- Filter posts with ajax form and checkboxes
- Filter custom post type archive page with custom taxonomies (categories) with AJAX
- Received nothing after executing AJAX post function
- Filtering WP_Query Dynamically on the Front-End
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Storing posts from query and accessing later via AJAX call
- Loading custom content type from ajax results?
- Ajax Custom Post Filter is not filtering
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- JS innerhtml changing style when using AJAX
- Custom post type editor with dynamic selects, one drop down populating a second second drop down not working
- Load Custom_post_type categories post with ajax
- Dynamic Custom Fields
- Retrieve custom post types by custom taxonomies with WP_Query
- Custom post type’s extra fields – how to handle?
- Combine multiple getEntityRecords calls
- filter by custom taxonomy using ajax
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- Not saving custom taxonomy while using ajax
- WordPress custom post type post item data – show/fetch only on click with Javascript dynamically?
- How to display custom post type pagination buttons when processing AJAX request
- Show ajax form resuslts in page
- Dropwdown: Get taxonomy terms from posts that share preselected terms from 3 other taxonomies
- Ajax load more inside custom post type taxonomy
- Custom filtering on month value only of an entire date field
- update custom taxonomy with Ajax in edit.php file [duplicate]
- How to filter custom post data with AJAX?
- Hide load more button if no more post in selected category
- Passing total post count to javascript
- Default post showing more than intended
- Load more post with AJAX
- Post current post type to my Ajax
- How to get all taxonomies of a post type?
- Permalinks: custom post type -> custom taxonomy -> post
- How to Add Tags to Custom Post Type?
- Mixing custom post type and taxonomy rewrite structures?
- Can multiple custom post types share a custom taxonomy?
- How to Add Custom Fields to a Custom Post Type?
- Efficient Taxonomy Intersection
- Display current taxonomy term when inside custom post type
- limit selection of custom taxonomies to one?
- $wp_query->queried_object->ID throws warning: Undefined property
- Custom permalinks – post type – hierarchical taxonomy’s
- Taxonomy posts on Archive page
- Taxonomy list. Order by a specific custom post type count
- Rewrite CPT slug with two taxonomy slug instead of one
- Archive or taxonomy pages not working for custom post type
- Custom Taxonomy returns no posts
- Display taxonomy term only if there’s a value
- Custom content type meta_box_cb does not run
- Custom Taxonomy breaking pages permalinks
- Custom post types and permalinks
- Problem with custom post types, taxonomy and permalinks
- How to create new category for custom post type?
- Fetch taxonomies by custom post type id array
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Normal pages as children of my Custom Post Type
- Remove url rewrites for registered taxonomies
- How can I auto-assign a CPT post to category in a custom taxonomy when published?
- Mapping Subdomains in WordPress to give the appearance of a localised site, best approach?
- Group CPT posts by custom taxonomy
- Metabox not show in categories custom post type cmb2
- Categorize custom post type
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- WP-API select custom taxonomy when creating a post
- List of Posts and Categories
- Custom taxonomy and post type with same slug
- WordPress Custom Post Type – show only certain posts that have specific taxonomy set
- Template for custom post type when taxonomy is in the URL
- I am trying to get cutom post cout by month of current taxonmy term
- Query custom post types & Taxonomies and list them in a table on a page
- Custom Post Type and Taxonomy Loop Output Is Wrong
- Nested Custom Taxonomies | Incorrect posts when querying
- Commas not displaying in implode
- add custom tags for custom post type in wordpress
- custom taxonomy listing returns no posts
- Display custom-post type based on the Title matching the current selected value
- How can I put content before my custom post type default pages?
- Custom front-end form for adding post – Category problem
- i want to send email to user when the custom taxonomy is changed
- Issues with static pages redirecting towards home.php
- Custom post type template – add banner under heading
- Store a value in global scope after init hook is fired
- Custom post type single page returning 404 error when sharing archive url with custom taxonomy
- Order posts by meta value hiding posts instead of re-ordering
- Looping through custom taxonomy in one template
- Change the url of a custom post type to include taxonomy
- How to query posts by meta keys AND under specific category?
- Shortcode display CPT Query only showing 1 post?
- Query Posts with Custom Taxonomy from a Custom Post Type
- How to show a custom taxonomy using a custom template
- Plugins for putting Custom Post Types into the Menu
- Custom term link return 404 error
- Remove slug from Custom Category Permalink + dual-category permalinks
- Display ONLY ONE $term (Out of 4 terms) from a Custom Taxonomy and CPT
- Calling custom taxonomies
- Limit taxonomy terms added to a custom post type
- Is it possible to use a post name in a custom post slug?