Skip to main content

Questions tagged [ajax]

Ajax - The core of WordPress uses Ajax only in the administration screens. For instance, Ajax is used for instant updates when you are doing comment moderation, and when you are adding and deleting items from lists such as categories, blogroll, and posts; Ajax is also the technology behind the auto-save functionality on post and page editing screens. Several themes and plugins also use Ajax; for instance, some post rating plugins.

15 votes
2 answers
39k views

Why use admin-ajax.php and how does it work?

My ajax call for json data works ok like this functions.php: add_action( 'wp_ajax_nopriv_load-filter', 'prefix_load_cat_posts' ); add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' ); ...
Claudiu Creanga's user avatar
14 votes
1 answer
14k views

Why use wp_send_json() over echo json_encode()?

When sending a JSON response back to an AJAX request, why use the WordPress function wp_send_json() and not echo json_encode()? What is the benefit of using the WordPress function wp_send_json() over ...
henrywright's user avatar
  • 3,077
14 votes
4 answers
8k views

Load minimum WordPress environment

I made my own upload service for my website that is separate from WP, but uses WP to provide low level db functions and user verification. To do that, I include wp-load.php in my main script (...
MechEngineer's user avatar
13 votes
2 answers
12k views

How would I get a taxonomy/category list inside a Gutenberg block?

I would like to display a dropdown list of categories (or other taxonomy) inside of a Gutenberg block. I can only think of two ways to do this: Create an array of the taxonomy in php and use ...
JakeParis's user avatar
  • 663
13 votes
2 answers
10k views

How can I send data to admin-ajax via JS Fetch?

I'm trying to implement filter system in my website. I decided to make it via js. I created fetch function let filters = document.querySelectorAll('.filters-item'); let pageUrl = wp.page_url; const ...
MMPL1's user avatar
  • 257
13 votes
1 answer
7k views

How to manage ajax calls and JSON in wordpress

I have a custom post type that i want to access through jQuery - preferably using JSON. So first things first. creating a function that returns/echos json is easy enough, but how would I access it ...
Storm's user avatar
  • 233
13 votes
2 answers
4k views

Can I use the same nonce for multiple requests on the same page?

Or does this break the purpose of the nonce, which I admint I don't quite understand it? :) For example on two ajax requests that run on page load, or when something is clicked: $.ajax({ type: '...
Alex's user avatar
  • 133
12 votes
2 answers
17k views

How to get a unique nonce for each Ajax request?

I've seen a couple of discussions about getting Wordpress to regenerate a unique nonce for subsequent Ajax requests, but for the life of me I can't actually get Wordpress to do it-- every time I ...
Tim's user avatar
  • 311
11 votes
2 answers
12k views

Open a Thickbox with content trough AJAX

I added a custom button to the TinyMCE editor, and I want to open WP's Thickbox when I click on it. How can I make it so that the tb_show() function loads the content I want with ajax? // the ajax ...
onetrickpony's user avatar
  • 13.6k
11 votes
1 answer
3k views

Initialize TinyMCE editor / visual editor after AJAX insert

I have a "repeater" style field group on a custom options page. There's an active visual editor in a hidden state, and when the user clicks "add new" the whole row is cloned. I then need to initialize ...
Jack Arturo's user avatar
10 votes
3 answers
21k views

Admin ajax request return 0 with die()

So i'm using this configuration for an AJAX call in the administrative area (like this): add_action( 'admin_head', 'ajaxPerNgg' ); function ajaxPerNgg(){ ?> <script type="text/javascript" > ...
Ivano Mercuri's user avatar
10 votes
2 answers
17k views

WordPress AJAX with Axios

I have a quick question. Did anyone managed to use Axios inside WordPress to do AJAX requests (wp_ajax with action - calling a function) not REST API and how did you do it? It seems that Axios is ...
Ratko Solaja's user avatar
10 votes
2 answers
5k views

Why is die() used at the end of function that handles an Ajax request?

What could go wrong if I am not using die(); after the function that handles an Ajax request? I have noticed that almost all the WordPress Ajax-based code is using it.
user avatar
10 votes
2 answers
9k views

ajax stopped working when not logged in?

Have had an autocomplete field working for months but has stopped working when not logged in? Not sure when but within the last few days or week (not updated wordpress recently). already have; ...
v3nt's user avatar
  • 1,689
10 votes
2 answers
2k views

Why not register shortcodes if is_admin dashboard?

I have noticed that some plugins such as Contact-form-7, Nextgen-gallery, possibly others, have an interesting anti-feature of not registering their shortcodes when is_admin() is true. The ...
NoBugs's user avatar
  • 452

15 30 50 per page