Ajax not posting form data to query in PHP function

I have probably found the problem (after our little discussion). For me it looks like the $postcode isn’t send. Check the “Headers” tab from you screenshot – there would be info about the POST variables that were or weren’t sent. If the $postcode isn’t send, you get from the query probably the codes that are … Read more

wp_create_nonce() in REST API makes user->ID zero

I know it pasts a long time of this question. But I had the same issue and it was difficult for me to find some documentation about it. I had the same problem, for some reason wp_create_nonce and wp_verify_nonce they bot retrieve different hash. So I notice the problem was the $User->ID or $uid that … Read more

Updating a checkbox value to database for specific row in table

Rough answer to get you started. Inside the loop, use the row’s record number (a field called ‘IDnumber’, unique, auto) to help name the of a . The hidden <input> should have an id of something like <input hidden name=”idnumber” value=”<?php echo $row[idnumber];?>”> which will cause the vaue of that input field to be the … Read more

Wp_query returning only one post while query through ajax

You are resetting the $output value in the loop. Declare an empty variable first, and then append each result to it in the loop: if($posts->have_posts()){ $output=””; while ($posts->have_posts()) { $posts->the_post(); $output .= get_the_title(); } } This will add all the posts to the $output variable.

Ajax Pagination on Ajax filter

As @Milo brilliantly pointed out, there is no such a thing like a global query object in WordPress. So I’ve solved the problem via JS, like this: var isFiltered = false; var filters; $(load_more_button).click(function(e) { load_more_handler(e); }); $(filters_form).submit(function(e) { filter_handler(e); }); function filter_handler(e) { isFiltered = true; filters = $(this).serialize(); var data = { action: … Read more

Getting back to ajax search results from a page

I solved this using the HistoryAPI. Since my ajax returns objects that has response, html and query, I pushed the html results of the search to the history state with window.history.pushState( date_out.html, null, null); where data_out is the object returned from the ajax call. Then I added a button on the single advert page that … Read more

get current custom post ID by WP_Query method

Since the AJAX can be called from anywhere, even by a search engine, you should pass the ID manually. To do this, you need to include the ID of your current page somewhere in your template. There is a common practice to include extra information in hidden input elements. You can add this hidden element … Read more

How can I access the Header of and ajax response from the rest API

You can use change ajax this: request.getResponseHeader(‘your_header’) $.ajax({ type: ‘POST’, url:’api-url.php’, data: formData, success: function(data, textStatus, request){ alert(request.getResponseHeader(‘your_header’)); }, error: function (request, textStatus, errorThrown) { alert(request.getResponseHeader(‘your_header’)); } });

How can I pass get_the_author_meta(‘user_email’) through the REST API?

Why I Don’t Have Access to Post’s Information? When you are using Admin-AJAX or the REST API, you will only have access to the current user’s data (by that I mean by default, such as using is_user_logged_in()). To retrieve any other information, you have to pass it as an argument in your AJAX request. WordPress … Read more