Tag Info

Hot answers tagged

5

Custom implementation vs. Standard API usage Using the WP AJAX API is the way to go. First off, you get access to the complete set of WP APIs, you can leverage standard jQuery $.ajax() and similar API calls and you are running standard conform, gaining access to all knowledge spread around the web with articles or for e.g. in answers on this site. In the ...


3

This is an add on to @kaiser answer, read that before. To be honest wp_localize_script, add_action are the best part of Ajax API, and really, they are an help, not a problem. Let's imagine you have 120 ajax functions. Even if you don't use admin-ajax.php see again your workflow: Check user is authenticated, if not, return a 403 header and exit(); ...


3

You are specifying the data type returned from the AJAX call to be JSON. However, the string you're returning ("batman begins") is not in JSON-format. Thus, the jQuery ajax-call will fail. Try passing your data as JSON using json_encode: function locationContent() { echo json_encode( 'batman returns' ); die(); } This will fix your issue. ...


2

I think this is what you want. base is set via home_url(), format is page/%#%/, search query arg is added via add_args if it exists: $args = array( 'base' => home_url( '/%_%' ), 'format' => 'page/%#%/', 'current' => max( 1, get_query_var('paged') ), 'total' => $temp->max_num_pages, ); if( isset($_GET['s']) ){ ...


2

Your code is a bit complex, so I can't post a full-working code, but a proof of concept, then adapt to your code is up to you. So, Ajax in WordPress should be used via Ajax API, instead to send a request to same url, that of course print header, and other stuff, simply send a request via Ajax Api and output what you want. I assume that you have a code ...


2

$mpcountrys is going to be an array or an object. In your case, an object, which is the default. One of four pre-defined constants. Defaults to OBJECT. See SELECT a Row and its examples for more information. https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results It looks to me like you probably want get_var() instead. And I ...


1

If you read the documentation for locate_template you'll see the problem. locate_template( $template_names, $load, $require_once ); $require_once (boolean) (optional) If true, the template file will be loaded with the php require_once function. If false, the template file will be loaded with the php require function. This parameter has no effect if ...


1

The Customizer will apply its changes into the frame over the entire site. Try it yourself with Twenty Thirteen and see. Make some changes, and without saving, navigate to a single post or single page and see how the changes persist even without saving. So likely you're doing something else that breaks that functionality in some way. In which case the ...


1

As you already know you can use wp_ajax_* and wp_ajax_nopriv_* hook to handle ajax request. Let see it with an example how it works. First we need to pick a Unique action key for our ajax request. For now say my_action. It is good idea to prefixed the key with your plugin name, so it would not conflict with others. Now define two hook. wp_ajax_my_action and ...


1

You should remove the link from the anchor tag: <a class="button" href="#" style="background-color:white;color:black;"> <strong>Submit</strong> </a> Then your jQuery part should be: $('a.button').click(function(event){ event.preventDefault(); //your ajax gets here: jQuery.ajax({ type:"post", ...


1

Couple of things: 1: When you include the script after jquery, localise it using the wp_localize_script function: $nonce = wp_create_nonce("vote_nonce"); $yourscript_info = array( 'ajaxurl' => admin_url( 'admin-ajax.php'), 'nonce' => $nonce ); wp_localize_script( 'yourscript', 'yourscript', $yourscript_info ); $.ajax({ type: "POST", ...


1

Here is a basic setup that I use for AJAX with Wordpress. instead of loading wp-load.php on a separate php file; just use Wordpress default method for AJAX calls. This allows you to also filter function calls from Javascript through a switch. I also added a quick example for wp_localize_script. <?php add_action('wp_enqueue_scripts', ...


1

WordPress does that by default at the end of admin-ajax.php. It kind of assumes you'll use one of wp_send_json(), wp_send_json_success(), or wp_send_json_error() to communicate your process' state (or at least terminate the script yourself). All of those use wp_die() to terminate the script after sending the response. It's sort of a catch-all response.



Only top voted, non community-wiki answers of a minimum length are eligible