Theme Customizer – Conditional Controls

I can suggest you another direction : why bother generating a new Control in javascript when you can create controls A and B at the first page load and hide/show them dynamically using javascript ? If I understand well, this was what you described in option 3. Here is a sample code to get you … Read more

Admin WP List Table Columns Missing

This is a bug with the wordpress AJAX trying to update manageedit-pagecolumnshidden on the admin table pages when columns are hidden. It completly breaks the entire admin tables when the table headers are visually hidden. Thanks to Michael Ecklund’s clue I was able to figure it out. I created the Ticket here: https://core.trac.wordpress.org/ticket/29030 And a … Read more

Can’t get result from sql using ajax result

I have made some changes to your code. See now if this works – function myajax_inputtitleSubmit_func() { // check nonce $nonce = $_POST[‘nextNonce’]; if ( ! wp_verify_nonce( $nonce, ‘myajax-next-nonce’ ) ) die ( ‘Busted!’); $zipcode = $_POST[‘zip’]; // generate the response global $wpdb; $tablename = “{$wpdb->prefix}levering”; $sql = “SELECT Levering FROM {$tablename} WHERE Zip LIKE … Read more

Show Post Content with AJAX

Create the JSON endpoint that accepts a WP_Post ID. add_action( ‘rest_api_init’, function() { register_rest_route( ‘api/v2’, ‘/post/(?<id>\d+)’, array ( ‘methods’ => ‘GET’, ‘callback’ => ‘get_post_content’, ) ); } ); Handle the endpoint to return a post’s content based on the ID passed. function get_post_content( WP_REST_Request $request ) { $post = get_post( absint( $request->get_param( ‘id’ ) ) … Read more

WordPress ajax success response

You can’t use 2 echos for an ajax response. Try this: js: $atj.post(MyAjax.ajaxurl, requestData).done(function(result){ console.log(result); if(result == ‘success’){ $atj(‘.training-form [type=text]’).val(”); $atj(‘.training-form-message’).append(‘<p class=”training-form-complete-message”>Thank you for the email</p>’); } }); php function myajax_submit() { // snip… $mail_check = wp_mail( $to, ‘Email Test’, $message ); remove_filter( ‘wp_mail_content_type’, ‘set_html_content_type’ ); if( $mail_check) echo ‘success’; else echo ‘failure’; exit; }

Loading post template that contains a nested loop with ajax

Your inner loop overwrites the contents of $post, so any later template tags use the values of whatever it last contained. “But I used wp_reset_postdata()!” you say? What that function does is try to restore $post from $wp_query->post. It’s meant to restore the main query after secondary queries. You have two secondary queries here, so … Read more

How to set post_id to 0 when you upload image via Add media button. (async-upload.php)

Finally found an answer for this and checked it worked on my situation. How to upload image without post ID using the new media uploader? // Set post_id to 0 when Add Media button clicked jQuery(‘#insert-media-button’).on(‘click’, function( event ){ event.preventDefault(); wp.media.model.settings.post.id = 0; }); This will set all the images uploaded via Add media button … Read more