Metabox cloning via Admin Ajax call issue

1st This isn’t a WP problem, but a jQuery problem. 2nd I used to develop my own set of classes for meta box and stopped about a month a ago and dropped them in favor of the RW Meta Box library. Meta Boxes are a big issue incl. saving the data, building an endless # … Read more

How-to debug wp_ajax_* hook callback?

The answer was as stupid as simple: I wrapped the init for the class in a ! is_admin() call. This successfully prevented the callback from beeing fired. Rule for AJAX loading Load it in public Don’t hide it behind a ! is_admin() call. The 2nd line from admin-ajax.php define( ‘WP_ADMIN’, true );

How to link WordPress heartbeat to ajax form

Saving data Based on Heartbeat API, you can add custom data to the sent heartbeat on heartbeat-send event in js. This would be used instead of the ajax function you have in your code example. jQuery( document ).on( ‘heartbeat-send’, function ( event, data ) { // Grab the required form data data.location = jQuery(‘input[name=”location”]:checked’).val(); data.userid … Read more

jQuery Autocomplete in WordPress

don’t include WP like that. use $_GET instead: … $(“#tags”).autocomplete(“<?php echo add_query_arg(‘get_my’, ‘terms’, home_url()); ?>”, … theme’s functions.php: add_action(‘template_redirect’, ‘terms_for_autocomplete’); function terms_for_autocomplete(){ if(isset($_GET[‘get_my’]) && $_GET[‘get_my’] == ‘terms’): $terms = &get_terms(get_taxonomies()); foreach ($terms as $term) echo “{$term->name}|{$term->name} ({$term->count} results)\n”; die(); endif; }

admin-ajax.php vs .load() in WordPress

Is it the only way to ajaxify your whole site or if there is any better way? No, it’s not the only way. As you already know, you can indeed use .load(). As to what’s better? That’s wide open to debate and depends on personal preference, requirements, circumstances etc. Cannot we use .load() method with … Read more

How do I send an ajax request and get a response back from a function?

$.ajax is very simple and you can append more parameters easily in the data: {action:’my_test_ajax’} line, try this: var target=”http://” + window.location.hostname + ‘/wp-admin/admin-ajax.php’; $.ajax({ url: ajax, data: {action:’my_test_ajax’}, type: ‘post’, success: function(data){ console.log(data, data.title, data.content) } }); Make sure the target points exactly to admin-ajax.php or set a global variable (or using localize script) … Read more

WordPress embeds in AJAX inserted content

I think the solution is amazingly simple here: You’re just missing a single line of code in your ajax callback, namely: global $post; where I assume you’re using: $post = get_post( $post_id ); The reason is that there’s a global post check in the WP_Embed::shortcode() method. More details in my answer here.