I am having a problem with two ajax action. I have a post grid it has a frontend sorting "ASC" and "DESC". So if I click on "DESC" it changes the WordPress query arg "order by" to "DESC". It works.
But I have load more button which is also ajax. It also works but it does not consider the above case it query args remain the same as initial. So if I click the DESC button and click load more it loads the second page without DESC into consideration.
Any possible workaround?
I am having a problem with two ajax action. I have a post grid it has a frontend sorting "ASC" and "DESC". So if I click on "DESC" it changes the WordPress query arg "order by" to "DESC". It works.
But I have load more button which is also ajax. It also works but it does not consider the above case it query args remain the same as initial. So if I click the DESC button and click load more it loads the second page without DESC into consideration.
Any possible workaround?
Share Improve this question asked Jan 4, 2020 at 19:39 user145078user1450781 Answer
Reset to default 0If you have a form you should have a sort field in it, so that you can send your order value on form submit. This way you can send the sorting parameter to your backend callback function. If you don't have a form you shoud add this parameter to another element with a data attribute like that:
<button id="load-more" data-order="DESC">Load More</button>
And then in your javascript code add this value to the ajax call parameters.
Remember that you should change this parameter when you call ajax for sorting.