Basic WordPress AJAX Call

WordPress AJAX uses actions to connect your jQuery action with a traditional WordPress action. Take a look at the example WordPress provides in their docs. There’s 2 hooks: add_action( “wp_ajax_{$jquery_action_string}”, “callback_function_name” ); The above will only work for authenticated ( logged in ) users. For non-logged-in users we use nopriv: add_action( “wp_ajax_nopriv_{$jquery_action_string}”, “callback_function_name” ); So … Read more

How declare Ajax functions ussing SHORTINIT

Build the PHP script that will handle the ajax resquest and send the ajax request directly to that filet (not to wp-admin/admin-ajax.php). In that file, first define SHORTINIT, then load WordPress manually and finally handle the ajax request. define(‘SHORTINIT’,true); //IMPORTANT: Change with the correct path to wp-load.php in your installation require_once (‘../../../../wp-load.php’); //Load any WordPress … Read more

Insert Post using Ajax

What says the error log? Is that the complete content of form-process.php? When it is so, then the problem might be, that the function wp_insert_post() is not defined, because the WordPress core was not loaded. Therefore WordPress has an AJAX-API. Here’s an example on how to use that API on server side: add_action( ‘admin_ajax_your_form_action’, ‘wpse_126886_ajax_handler’ … Read more

Proper way to load a single post via Ajax?

Here is my view: Load it inside your single.php why use ajax at all? Google wont be able to see this (using most crawlers). In any case – here is the right way to return the data… please note that you can use get_post or wp_query. up tp you. JS Part: jQuery(document).ready(function($) { $.post(ajax_object.ajaxurl, { … Read more

Trying to load content of a post via AJAX

If your javascript action is named ajaxify, then these should be: add_action(‘wp_ajax_ajaxify’, ‘ajaxify’); // ajax for logged in users add_action(‘wp_ajax_nopriv_ajaxify’, ‘ajaxify’); // ajax for not logged in users the actions you hook are a concatenation of wp_ajax_(nopriv_) and your action name. the function that’s hooked to that action can have any name, so it could … Read more

how to use ajax in plugin admin area?

Please, avoid the use of require(‘../../../wp-load.php’); and things like that as suggested in other answers. You should always use the WordPress AJAX way. It is really easy and you will have all WordPress engine loaded in your PHP script. Just three considerations: You have to send the ajax request to …wp-admin/admin-ajax.php. ajaxurl is a javascript … Read more

Passing a varible from jQuery to PHP

First, don’t use query_posts. Second… I think this can be done with AJAX but is there a more simple method and give me a clean URL? PHP runs on the server. Items are “clicked” on the client machine. The only way to pass that “clicked” value back to PHP is via AJAX. Within a WordPress … Read more