admin-ajax returning 400 error when request is made with Fetch API

To make a working HTTP request with fetch API you have to do something like this. const form = new FormData(); form.append(‘action’, ‘make_appointment’); form.append(‘post_title’, ‘hola como estas’); const params = new URLSearchParams(form); fetch(ajaxSettings.ajaxurl, { method: ‘POST’, credentials: ‘same-origin’, headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded’, ‘Cache-Control’: ‘no-cache’, }, body: params }).then(response => { return response.json(); }) .then(response => … Read more

Multiple ajax nonce requests

That is basically the way WordPress does it and pretty much the only way to do it, simply have your receiving PHP function create a new nonce add send it back with your response, then just update the value on your JS before the next round.

Is having multiple theme customizers for different pages possible?

This is not a complete solution and the code is not tested, but I it should be enough to give you a general idea of how to use the customizer for different pages. // Add “Edit page with customizer” link to relevant pages add_action(‘admin_bar_menu’, function($bar) { if (is_home()) { $bar->add_node(array( ‘id’ => ‘some-id-1’, ‘title’ => … Read more

Including WordPress in RESTful API

The credit for this answer really goes to @Wyck who correctly identified the source of the problem. Thank you very much. The reason for the problem is: There is a variance between an import statement in the mainline code versus within a function. In WP or in in any of the plugins if variables aren’t … Read more

WordPress AJAX Pagination with query_posts

In the end I found that it is not possible to update the pagination. The way I loaded the next lot of posts was by setting a post offset, and using a load more button. So in your ajax call where you are loading more posts, you need to pass over an offset value: $.ajax({ … Read more

Help making my pagination plugin better

Ok, here are some pointers: never run any meaningful code right from plugin body (especially don’t start queuing jQuery everywhere like you do – that’s asking for trouble), always do it at appropriate hooks; learn how to use $default argument in get_option() will save you a lot of typing there; learn how to use plugins_url() … Read more

Using wp_send_json to return HTML

I can’t tell what the $my_page, $my_page, or $shipHelper variables are supposed to do, but you can use an output buffer to capture the output of your DisplayEventInfoBox function. You can try the following: function myAJAXFn() { ob_start(); DisplayEventInfoBox($my_page, $shipHelper); $my_html = ob_get_contents(); ob_end_clean(); wp_send_json_success( array(‘page’=>$my_html) ); }