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
- Getting the Intersection of Two Custom Taxonomy Terms for a Custom Post Type?
- Why does my custom taxonomy show a total count across all post types
- Custom Taxonomy’s Label to change the text appearing in Appearance > Menu
- Custom Post Type with Nested Taxonomy and Template Files
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- 404 error PageNavi custom type taxonomy | wordpress
- Query for posts in 2 taxonomies
- Custom post types – show specific posts
- custom taxonomy archive by year
- Can custom taxonomies items have attached properties?
- Associate custom post types with normal posts
- WP 3.0.5 – Custom posts matching 2 taxonomies
- Custom Post Type Loop within Shortcode
- Custom Taxonomy URL are redirecting to page with the same name
- Loop custom taxonomy to get lists of cutom post types?
- Hierarchical Custom Post Types in Array
- Making certain categories of CPT not publicly queryable
- Query with no terms uses index.php template instead of archive.php
- Show a Category X’s custom post type on Category X archive page?
- custom taxonamy and post type
- custom-taxonomy/post_name instead of the default post_type/post_name
- Getting categories of posts under a custom taxonomy
- Custom taxonomies relationship
- Load Next Posts With AJAX not working with custom post type
- Custom Taxonomy not being saved on custom posttype
- Add term to custom post type on draft
- Multiple tag cloud filtering
- Custom Post Type Category Link
- Show all tags on custom post type
- Custom Post Type Slick Slider “$ is not a function”
- Get parent category id from child category page for custom taxonomy
- Trying to get custom post of a custom taxonomy
- How to get only child terms from a custom taxonomy of current post type?
- How can I create an automatic drop down menu with my tags?
- Get taxonomy singular name instead of taxonomy slug inside $taxonomy query
- sort CPT on Custom Taxonomy Archive page
- Cannot choose custom categories for custom post type in post editor
- Modifying rewrite rules to use /category//
- Multiple wp_editor instances in custom post type using Ajax
- Custom Post type Query by Taxonomy
- Custom post not appearing under custom taxonomy category
- Order custom posts by taxonomy, then by meta_key
- Safe to throw 404 error in request filter?
- How to filter Multiple taxonomies with radio buttons
- ACF – Retrieve custom taxonomy from a relationship field
- Restrict access to custom post type based on its taxonomy terms
- Create loop from selected terms in ACF taxonomy field
- Sort custom posts by date and then by taxonomy
- How to select custom posts thats are tagged with multiple taxonomies using wpdb
- How is possible to know ID of taxonomy-{taxonomy}.php page for ACF fields
- Display CPT Category List as Shortcode
- Aloha! VERY broad CPT questions. Looking for the theory/best practices behind it
- Dont know why my custom post type not add_post_meta
- Custom post type single with custom URL structure
- WordPress custom post type taxonomy paging
- List posts that have the current url taxonomy
- Display title of all custom posts from same taxonomy term on a custom post template
- wordpress does not see the correct custom taxonomy hierarchy
- How to build overlapping custom post_type and taxonomy rewrites without conflicts?
- How to get all posts assigned to a taxonomy term only?
- Custom Taxonomies in body class with parent slug
- Generating a radius search on postmeta-metavalue and adding a taxonomy to query
- How to pass taxonomy terms to WP_Query along with $args?
- Changing custom taxonomy’s slug as required?
- Archive custom template from search
- Changing checkbox array from single to multiple select
- Get all terms assigned to a post from different taxonomies
- An script/Plugin for automatic page creation per term
- Add Shortcode functionality to a function that queries custom post type / taxonomy