Storing temporary data for a custom post type

If you’re using custom post types, i’d save those date entries as post_meta entries (http://codex.wordpress.org/Function_Reference/add_post_meta). So if your client clicks on a date, you start an ajax request to your plugin/theme file to add or remove a meta entry. you can create one meta_entry named _availability for example and save all dates there (you can … Read more

How to call ajax in plugin file

Use the built-in wordpress Ajax actions: Your jquery will look like this: $(‘#ajax_form’).bind(‘submit’, function() { var form = $(‘#ajax_form’); var data = form.serialize(); data.action = ‘MyPlugin_GetVars’ $.post(‘/wp-admin/admin-ajax.php’, data, function(response) { alert(response); }); return false; Your plugin code something like: add_action(“wp_ajax_MyPlugin_GetVars”, “MyPlugin_GetVars”); add_action(“wp_ajax_nopriv_MyPlugin_GetVars”, “MyPlugin_GetVars”); function MyPlugin_GetVars(){ global $wpdb; // use $wpdb to do your inserting //Do … Read more

admin-ajax.php (aborted) error when using jQuery.get

Are there any Console js errors? The admin-ajax.php is WordPress’s built in way of dealing with ajax so you should probably do something like this, assuming .get() would also work: $.post(ajaxurl, data, function(response) { alert(‘Got this from the server: ‘ + response); }); http://codex.wordpress.org/AJAX_in_Plugins

wp_ajax handler with multiple class instances

Your McAdmin seems fine – the problem is likely one of two reasons: Another AJAX hook for blubb is terminating the script before McAdmin::get_vehicle You need to add the same hook for wp_ajax_nopriv_blubb – for non-logged in AJAX requests (otherwise it fails silently). If neither is the cause, you need to do a little HTTP … Read more

AJAX – SHORTINIT set to TRUE returns blank

You are using esc_attr(), which isn’t available if you use define( ‘SHORTINIT’, true ); , see source. So you either have to load the formatting.php manually or have to ditch the define( ‘SHORTINIT’, true ); – actually like the example in the thread you are referring to shows. As said in the comment, I checked … Read more

Contact form – ajax, wp_mail

From quick look at your code you seem to be omitting where you are submitting request to. By default it is just current page, which isn’t typically equipped to receive the request. Since you are using wp_ajax_ hook you need to point request at admin-ajax.php endpoint. On admin side the URL is provided in ajaxurl … Read more

How to update post with Ajax (no plugin)

This question is old, but for future reference, check out the answer I gave on the original question here. The gist is: Confirmation Dialog The alert is generated in wp-admin/js/post.js and wp-includes/js/autosave.js. Theoretically, you should be able to use the following line of code in your $.post success function: wp.autosave.initialCompareString = wp.autosave.getCompareString(); But that doesn’t … Read more

Custom RPC end-point security best pratice?

I think your paradigm is not optimal. You are starting on premise of “WordPress Ajax endpoint is slow” and your solution is to “build alternate authentication scheme”. This completely spells trouble. Anything security should be reused as much as possible and coded by people specializing in security. Trade-off of reimplementing security for the sake of … Read more

Use AJAX in a WordPress Plugin to Get Data From Custom Database?

You can use like this for send ajax… function my_action_javascript() { ?> <script type=”text/javascript”> jQuery(document).ready(function ($) { var data = { ‘action’: ‘my_action’, ‘whatever’: ‘1’ }; $.post(ajaxurl, data, function (response) { if ($(‘#menu_order’).val() == ” || $(‘#menu_order’).val() == ‘0’) $(‘#menu_order’).val(response); }); }); </script> <?php } add_action(‘admin_footer’, ‘my_action_javascript’); function my_action_callback() { $whatever = intval($_POST[‘whatever’]); //$whatever += … Read more