This line in functions.php is your problem:
$cat_id = get_post_meta($_REQUEST['cat']);
I think you are misunderstanding the purpose of the get_post_meta() function. It is designed to get metadata for a WordPress Post, not data from a POST request to the site. The first parameter of the get_post_meta() function is the $post_id, but since you are passing the category ID instead, you’ll either get false or an array of all meta values if a post with the same ID as that category ID exists. In either of those cases, the value of the cat query var will not be a valid categroy ID, and so that part of the query will be ignored and all posts will be returned. If you change that line to this, it will fix that problem and your code will probably work:
$cat_id = absint( $_REQUEST['cat'] );
The absint() function just converts the user-supplied value into a positive integer.
Related Posts:
- How to add defer=”defer” tag in plugin javascripts?
- How to add a custom CSS class to core blocks in Gutenberg editor?
- Why is javascript allowed in my post content?
- How to pass/get data to/from the WooCommerce data-product_variations object?
- Remove left alignment option in core/image block
- How can I send data to admin-ajax via JS Fetch?
- Shortcodes not resolved in AJAX call response
- Ajax, filters and shortcodes
- Multiple Ajax Data Action
- How can I filter block registration based on post-type? (Block alignment settings)
- Add attribute to script loaded by the theme
- When to use add_action when registering/enqueuing scripts
- Are there actions or filters I can use for Ajax calls?
- Remove CSS & JS files from WordPress Main Page For Increase Pagespeed?
- Does a plugin with a AJAX button filter exist? [closed]
- wp_mail works with add_action(‘save_post’, …) but not an ajax action
- Is it possible to bind a function to a filter hook via Ajax?
- How To Override A WooCommerce AJAX Function
- Best practice: Custom Post Type / Filter / Load more
- How do I add tags to entire comments, not just their text
- Running JavaScript after using WooCommerce Filter Plugin
- “The editor has encountered an unexpected error” After add defer tag to java script
- Ajax filter – show all results that contain at least one filter
- AJAX Post Filter
- How to bridge the gap between dynamic back-end data and front-end output?
- Display post after choice two taxonomy terms
- Ajax Filtering Pagination
- Change add_filter based on Ajax
- Filter posts by categories ajax is showing all the posts
- Code restricted to dashboard, running unexpectedly in the frontend (pre_get_post and admin-ajax.php)
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- Loading a sidebar on an Ajax call
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- Limit total tags in the_content
- How could I create real-time filtering in this case?
- Load More : Admin Ajax 400 Bad request, returning 0
- Is SAJAX dead? What to replace with?
- Access Control Request Headers, is added to header in AJAX request with jQuery
- React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
- How to manage a redirect request after a jQuery Ajax call
- WordPress hooks/filters insert before content or after title
- Query WP REST API v2 by multiple meta keys
- Removing Image and Caption Dimension Attributes
- AJAX with loop filtering categories
- How to apply the “retrieve_password_message” filter?
- Store source permalink on XMLRPC calls
- How to limit the pages displayed for choosing parent page on page attribute’s menu?
- Filter keywords from search query
- Add class to woocommerce checkout body based on filter [closed]
- changing variable through filters or action hooks
- Changing Gutenberg / WP block editor width only on pages, not posts or other taxonomies
- How to replace any occurence of Gravatars with a local placeholder image?
- How To Get User Data in Callback Function for pre_user_nicename?
- What’s the best way to split admin-only functionality in the theme’s functions.php file?
- Which built-in WordPress files are safe to edit?
- Why won’t my preg_replace work with content_save_pre?
- Trying to implement Ajax comments in WordPress, getting WP error
- How do I target a single page to modify the comment form of only that page?
- How Does comment_author Filter Work?
- Contact Form 7 filter similar to preprocess_comment [closed]
- Walker_Nav_Menu doesn’t work in wp_page_menu_args filter
- get_posts() and filters
- upload_files cap to not loggen in users – add_cap to not logged in users
- WooCommerce Ajax Cart Update Stopped Working
- How to filter backend post list showing only posts having a shortcode
- Add Lightbox To WordPress Native Gallery
- Modify Redux Framework Options in Child Theme
- Contact Form 7 Custom Validation Doesn’t Get Called [closed]
- wordpress add_action() issue in ajax call
- Dequeue script to prevent javascript event conflict on wordpress child theme
- Trimming a custom field to a length
- How to hide/remove GhostKit component panel in gutenberg block inspector
- wp_mail doesn’t work when logged in?
- when use function the_content break
- Filter page title (displayed in browser tab) of wp-login
- Adding html banner to posts
- admin-ajax.php (aborted) error when using jQuery.get
- How does wordpress add ‘style’ attribute to element
- Filter “Your latest posts”
- Hide certain product filters from specific product categories
- Hooked into wp_get_attachment_caption to add content to the default description; not working for jetpack slideshow. Why?
- Admin-ajax.php 404 error
- Removing menus from users other than the administrator
- Can’t understand apply_filter logic
- Overriding Plugin function in your child theme
- How to submit form data in the same page in WordPress without reloading the page?
- How can I add a prefix to titles displayed in sidebar using function.php?
- List all image sizes still getting disabled sizes
- Why this remove empty paragraphs from the_content does not works?
- What problems could happen if I replaced add_filter and add_action with the function calling
- change attachment custom field onChange event
- Adding to an array & passing it through do_action/apply_filters
- the_excerpt() does not work with has_excerpt()?
- Stop loading more posts if none left AJAX
- Custom excerpt_more filter not working when tag is present
- Taxonomy search filters
- Modify the third (context) parameter in a filter?
- Adding filter to the Contact Form 7 response
- Remove rel=”ugc” from links in comments
- How to increase comment length?