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
- Ajax load more post button not showing
- WordPress Custom Post types and Taxonomy relationships best practices
- List custom post type by custom tax term as page title
- Output the content of a term organised by each of the CPT?
- How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- Permalinks when filtering multiple custom post types by single taxonomy
- removing custom tax & CPT slug, adding taxonomy term in front of custom type
- Custom Taxonomy Creates Unwanted Integer Terms on Post Save
- Order WordPress Custom Taxonomy Pages & Pagination Not Working
- Adding the taxonomy before the custom post type
- multiple url slug for single custom post type
- Custom post type and taxonomy permalinks – Structure
- Add hierarchical taxonomy to permalink for custom post type
- Best action hook to create custom post and assign taxonomy terms to it on plugin activation?
- custom taxonomy archive by year
- Pretty URLs for Custom Post Type & Custom Taxonomy with Duplicate Slugs on WPML
- Custom Post Type and Custom Taxonomy Permalinks
- Can I change the slug of my archive page on a Custom post type?
- Ajax form filter post by custom fields [closed]
- How to filter the taxonomy terms based on another taxonomy term
- Custom Posts Hierarchy? (State/City/Restaurant)
- Custom post types, taxonomies, and permalinks
- How to sync tags between posts that are linked through Posts 2 Posts?
- Custom Post Type with two hierarchical Custom Taxonomies: strategy to generate best permalink structure
- Automatically populate a hierarchical taxonomy from a custom field
- Add nonexisting pages to navigation
- How can I display my custom metaboxes on a custom post template?
- How to specify URLS for custom posts & taxonomies
- Custom post types, taxonomies, and permalinks
- Custom post types and permalinks
- Custom Post Custom Taxonomy Data Not Saving in Edit Screen
- Custom Post Type vs. User Page
- How to rewrite custom post type with custom taxonomy urls?
- Relationship between two taxonomies and a custom post type [closed]
- Sharing a custom taxonomy with Multiple custom post types
- CPT Search Form with Taxonomy filter & Or
- Display custom post type category taxonomy
- How to load custom post archives sub-pages with ajax?
- How-to leverage WordPress for creating Extended Social Profiles
- Display custom post type taxonomies as an archive page
- Menu Multiple Taxonomies
- Generate Shortcodes by Taxonomy
- Custom Taxonomy Not Showing in Menu
- How to customize admin posts based on the user who is logged in
- How is this CPT code in functions.php adding a hidden “products” category?
- taxonomy template for custom post type the same as the archive
- How to get posts from multiple custom post types according to it’s custom taxonomy terms?
- Set object terms not working on plugin activation
- Display only post types that are direct children of the current taxonomy
- Get categories and descriptions from custom post type
- Custom Taxonomy – Tags Metabox is showing instead of Categories
- Combining custom post type and post category
- Is it possible to create a shortcode that will query a post based on taxonomies?
- Keyword search limited to specific post type filtered by multiple custom taxonomies?
- need advice on how to do a lists using custom post types – taxonomy vs postmeta
- next_post_link on custom taxonomy
- Taxonomy.php Not Showing Posts
- Show Two custom Post type and their posts on category page
- wp_query to find posts by year and month
- How to make a custom taxonomy selectable in post publish area?
- How to filter custom taxonomy categories on archive?
- How to create an advanced filter search?
- What is the use of a custom taxonomy?
- Count posts with specific term_meta
- Custom post type custom taxonomy archive page name
- How to output wordpress custom tags separated by comma?