Hello - I know there are already a few topics around AJAX filtering (one created by myself), but to my knowledge there is still no fully integrated working solution out there, and the demand for it is quite big.
After numerous attempts to create the code for it myself, I think I am close to achieving a working version (leveraging the master code hivepress/includes/blocks/class-listings.php at master · hivepress/hivepress · GitHub suggested by @ihor in another similar topic), but I need some help from the community.
Right now, when I click on an category filter, no front-end error message appears but also no listings are displayed (although there are existing listings respecting the filter). However, if I try to select an attribute filter, it gives the error message (hardcoded by me) “No listings found that match your criteria”. (again, despite listings existing).
My debug logs show that the WP_Query finds the posts, the loop runs, and the Listing object is found correctly. However, the render() method returns an empty string for every post. For example, here are the logs from one filter attempt:
Debug AJAX: Found 8 posts. Starting render loop.
Debug AJAX: Loop iteration for Post ID: 649
Debug AJAX: Successfully got Listing object for ID: 649
Debug AJAX: Attempting to render template for listing ID: 649
Debug AJAX: Render SUCCESSFUL but output is EMPTY for listing
This proves the listing-view-block template is failing silently during the wp_ajax_ call, most likely because a function or service used inside the template is not initialized. For context, I will also add the code in the comments.
I guess the next question that could hopefully solve this last bit is: What is the correct method to reliably query listings AND render the listing-view-block template during an AJAX request handled via admin-ajax.php? Standard methods seem to be failing due to these initialization issues.
Thanks a lot!