Forums › Forums › Search & Filter Pro › AJAX query not working properly when excluding taxonomies
- This topic has 7 replies, 2 voices, and was last updated 8 years, 9 months ago by Ross.
-
Anonymous(Private) March 9, 2016 at 6:49 pm #39072
As explained in this post: link, there seems to be a problem when loading with AJAX the results of the query and having excluded some taxonomies.
The query goes like this:
SELECT SQL_CALC_FOUND_ROWS wp_ifxo_posts.ID FROM wp_ifxo_posts WHERE 1=1 AND wp_ifxo_posts.ID IN (15949,15952,15954,16384,16415,16416,16417,16422,16423,16424,16425,16426,16427,16428,16429,16430,16431,16432,16433) AND (
0 = 1
) AND wp_ifxo_posts.post_type = ‘video’ AND ((wp_ifxo_posts.post_status = ‘publish’ OR wp_ifxo_posts.post_status = ‘inherit’)) GROUP BY wp_ifxo_posts.ID ORDER BY wp_ifxo_posts.post_date DESC LIMIT 0, 25Please note the 0 = 1, which will always turn FALSE and return no results. This happens only after applying a filter on the page. So when one access the URL with a URL query (like filtering), the results are correctly displayed.
This could mean the AJAX query construction is slightly different and hence returning a wrong query.
Looking forward to the fix.
Ross Moderator(Private) March 9, 2016 at 6:52 pm #39075Hey Daniel
How are you excluding taxonomies? Via the S&F UI?
Thanks
Ross Moderator(Private) March 9, 2016 at 8:19 pm #39094Ah ok, well in this case, I really think something in your setup is interfering with the ajax request.
When S&F makes an ajax request, usually, it just loads the result page, and extracts the HTML out of there (I think you won’t have any issues with ajax using any of the other display methods).
However, using a shortcode allows for a much smarter & faster kind of ajax request – but it is retrieved from another URL – if you check your network requests when doing an ajax search using the shortcode method, you will see url like:
yoursite.com/?sfid=12567&sf_action=get_results
It seems that the query performed here is be interfered with (S&F uses the exact same function to build the query)
Something like a
pre_get_posts
filter in your theme or a plugin I *think* would cause this.So I think the doing the following is the best course of action:
1) disable all other plugins and test again
2) test with another theme
3) use a filter to make the exclusion manually: https://www.designsandcode.com/documentation/search-filter-pro/action-filter-reference/#Edit_Query_ArgumentsI have just tested locally and on a dev server and am not getting the same issue as you :/
Let me know how it goes
Thanks
Ross Moderator(Private) March 9, 2016 at 8:22 pm #39097FYI, we only use the WordPress query API – S&F does not write any SQL into the WP_Query – we only use the methods available here
https://codex.wordpress.org/Class_Reference/WP_Query
Which means that there is no code adding in anything like a
(1=0)
to the query.Thanks
Anonymous(Private) March 10, 2016 at 12:54 pm #39143Hi Ross,
I’ve made some tests following your advise.
I searched for the
pre_get_posts
without success, so I don’t think is that.
I did however found out that the plugin Enhanced Media Library when disabled was making the results to be empty.
I also made my own filter using the code on my own plugin and it was working in the same way as your plugin through the UI.Conclusion, AJAX is still not working and the only way I can use an exclude is by not using AJAX, which is a shame as my results are slower in being displayed.
If you want, I can give you access to my site so you can check it?
Thank you
-
AuthorPosts