最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - how to handle multiple ajax wordpress queries?

programmeradmin7浏览0评论

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 user145078user145078
Add a comment  | 

1 Answer 1

Reset to default 0

If 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.

发布评论

评论列表(0)

  1. 暂无评论