How to add a do_action on refreshing of WP customizer?

Got the solution: Create a PHP file “purge-bb-cache.php” Create a JS script like below in functions.php purge-bb-cache.php <?php FLBuilderModel::delete_asset_cache_for_all_posts(); ?> JS script: // Add JS to customizer function print_customizer_js() { ?> <script> // Purge BB Cache On Save Customizer jQuery(document).ready(function(){ jQuery(“input#save”).click(function(){ //var ajaxurl = “<?php echo ( get_stylesheet_directory() . ‘/wp-content/themes/bb-theme-child/script.php’ ); ?>”; jQuery.ajax({ type: ‘POST’, … Read more

Customizer AJAX using buttons

Having any AJAX inside of the customizer defeats the reason for using the customizer in the first place. The idea of the customizer is that it fully controls the state of the settings while it is active, and having any setting being updated without going via the customizer logic can actually cause a mismatch between … Read more

Ajax comment form submit on frontpage alerts success but no insertion

It took a while, but this works (a comment is created, albeit with still some missing values, but fixing that part is easy) Biggest changes: For some reason an ‘echo’ in functions.php was important. Also, I changed the ‘action’ in ajaxtry2.js under data: HTML (values are fictional) <form id=”commentform” class=”commentform”> <label for=”comment”></label> <textarea id=”comment” class=”comment” … Read more

WordPress + JavaScipt + AJAX + MySQL: insert query for form

I’ve cleaned everything a little bit. Now it looks like that: ajax.js function ajaxSubmit(e){ var nazwa_szkolenia = document.getElementById(“nazwa_szkolenia”).value; var Data_szkolenia = document.getElementById(“Data_szkolenia”).value; var Godzina = document.getElementById(“Godzina”).value; var Max_pacjent = document.getElementById(“Max_pacjent”).value; var dataString = []; dataString[‘nazwa_szkolenia1’] = nazwa_szkolenia; dataString[‘Data_szkolenia1’] = Data_szkolenia; dataString[‘Godzina1’] = Godzina; dataString[‘Max_pacjent1’] = Max_pacjent; if (nazwa_szkolenia == ” || Data_szkolenia == ” || … Read more

Ajax with plugins returns 0

You can turn your AJAX requests into a REST endpoint to get rid of this common 0 response. All you have to register 2 REST routes for your requests: add_action( ‘rest_api_init’, function () { //Path to approve comment register_rest_route( ‘john_doe/v2’, ‘/approve_comment/’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘approve_my_comment’ ) ); // Path to delete comment … Read more

How get child posts in custom post type by ajax?

To retrieve the post details you have to send the data yourself. In your JavaScript code you did not send post id. Update your code like this: data:{ action: “applications_filter”, post_id: current_post_id, //current_post_id should either parsed from DOM or you can write your ajax in PHP file } You must need to send post_id before … Read more