0

I created a widget with additional settings fields (orderby etc.) that displays users using new WP_User_Query( $args ).

I also created a follow user button. I was able to successfully use ajax to update the database, show custom message and more.

Now I've reached the point where I want to update the list of followers inside the widget (with AJAX) once follow user button has been clicked. but I'm not sure how to tackle this one.

Output of the widget is placed inside a container class, so it will be easy to target this class inside the ajax success function.

<div class="follow-me-container"> 
<table>...</table>
</div>

Based on online tutorials, I've to completely rebuilt the query inside the wp_ajax_ function. However, the widget uses predefined settings which I want to keep.

Any help in the right direction is much appreciated.

  • Can you provide us your php wp_ajax_ function and js? – Anton Lukin Aug 29 '17 at 18:16
  • I haven't started adding the code that is relevant to target the widget/container class. The code I have so far is only related to updating the database, custom message, buttons, etc. – kiarashi Aug 29 '17 at 18:23
  • Is there a particular reason you're using the old Admin AJAX API and not the new REST API endpoints? – Tom J Nowell Aug 29 '17 at 18:27
  • Not really, I've been reading up a lot about using AJAX in WP, so I started to give it a try. Is AJAX outdated? – kiarashi Aug 29 '17 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.