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
- My javascript is returning this error: $.ajax is not a function
- Uncaught TypeError: Cannot read property ‘appendChild’ of null
- Download a file by jQuery.Ajax
- How to filter users on admin users page by custom meta field?
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Modify the post/entry wrapper markup in genesis childtheme [closed]
- post_row_actions filter is not working while update post using quick edit
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- get_the_excerpt() with fallback like the_excerpt()
- How to link current user to their author page through shortcodes
- Taxonomy Custom Column – ‘manage_{TAXONOMY}_custom_column’ filter only passing 2 arguments
- How to get list of all hooks of current theme / plugin?
- Elegantly using JavaScript on widget admin forms
- Can you use add_filter() inside other function?
- WordPress AJAX Call Not Return Result
- is there a specific place where add_filter must be placed?
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- add_filter() function misunderstanding
- admin-ajax.php responding with 0
- WordPress ajax function parameter value not being passed
- Filter my args by the post 1st letter
- Adding Filter to Homepage only
- the_excerpt filter with an empty excerpt
- Does auto_update_plugin Filter Work When Put In Theme’s functions.php File
- In need of a content replace filter for posts in a specific wordpress category
- remove inline scripts from the_content() produced by plugins?
- Inline Styles on all native blocks
- How to filter post content and force every link () made in blocks to return urldecode() with readable value?
- Image upload via FormData API and AJAX is not working ($_FILES always empty)
- Changing WordPress core without hacking core
- Link to Shop-Filter with .current-menu-item
- Remove posts inside pre_get_posts using a custom query
- Remove / Hide Attachment Display Settings in Add Media popup / dialog
- how to customize rss feed tags using hooks?
- Is it possible to apply filter to meta key value when querying posts?
- apply_filters with multiple args and multiple add_filter
- AJAX wp_insert_user WORKS but responds with “The site is not enabled”
- How can I specify the post status of an untrashed post?
- How to use a dropdown to filter posts by custom field
- Incrementing PHP variable onclick to display posts by month
- Rewrite rule and display of post
- Passing variable from child theme function to parent theme filter
- paginate_links() Change the order of links
- Add Filter – Pass Variable (PHP < 5.3)
- Ajax URLs without #!, how to prevent falling into single.php on load or reload?
- Why does admin_body_class not work?
- Variation prices breakdown only for single product page
- Trouble with AJAX using GET
- Edit Post Permalink option removed, looking for possible causes
- How to use wp_ajax_set_post_thumbnail?
- How to track a particular page in order to address the loading speed issue
- how to overwrite next_post_link
- Ajax call from Plugin using Class
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- How to check which submission button was clicked?
- filter wptexturize doesn’t work on old posts titles
- remove_action conditionally for Custom Post Type – not working
- wp_get_attachment_link filter not working
- apply_filters, EMBEDS and AJAX not a friends? [duplicate]
- Using Javascript Callback from plugin in a theme
- Getting entry ID from frm_email_message filter in formidable
- Is there a hook or filter that adds a button to the left of the search box?
- Replacing text using add_filter
- Background color and background image below element in Contact Form 7 – error tip [closed]
- Change password reqts with NO plugin without breaking resetpass link?