Loading a sidebar on an Ajax call

is_admin() returns true if you’re doing an Ajax request. So this is why my code didn’t work. Instead I’ve done this: add_filter( ‘loop_start’, ‘my_sidebar_widget’, 25 ); function my_sidebar_widget() { if ( is_active_sidebar( ‘my_sidebar’ ) && (defined( ‘DOING_AJAX’ ) && DOING_AJAX ) || !is_admin() ) { echo ‘<div id=”my_sidebar”>’; dynamic_sidebar(‘my_sidebar’); echo ‘</div>’; } } defined( ‘DOING_AJAX’ … Read more

Ajax, jQuery and WordPress

Wrap your javascript code with document.ready, and if it works I would suggest going back to putting this in an external file jQuery(document).ready(function(){ jQuery(‘#ajax_form’).on(‘submit’, function(e) { e.preventDefault(); console.log(‘Here’); var form = jQuery(‘#ajax_form’); var data = form.serialize(); data.action = ‘add_word_to_form’ jQuery.post(‘/wp-admin/admin-ajax.php’, data, function(response) { alert(data); }); //return false; }); });

how to use get_field_name in external ajax handler

Why you want to use ajax for showing some fields on form in widget? Can’t it be done using simple show hide using jquery. See below. Not tested , just to give insight. HTML <input type=”radio” id=”someradio” /> <div id=”somediv” style=”display:none;”> <input type=”text” name=”<?php $this->get_field_name(‘name’); ?>”> </div> Jquery <script type=”application/javascript”> jQuery(‘#someradio’).on(‘click’,function(){ jQuery(‘#somediv’).toggle(); }); </script>