Ajax object not defined – JS file is in plugin folder

You have registered your JS code in wrong hooks . Always CSS and JS should be registered using wp_enqueue_scripts. Also you have only registered your JS code. You have not enqueued your JS file using wp_enqueue_script( ‘ajax-send-notification-script’ ); function ajax_send_notification_init(){ wp_register_script( ‘ajax-send-notification-script’, plugins_url() . ‘/plugin-name/js/the-plugin.js’, array(‘jquery’) ); wp_localize_script( ‘ajax-send-notification-script’, ‘ajax_send_notification_object’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ … Read more

Is there a better way of handling AJAX requests in WordPress?

Use add_rewrite_rule to make your own API and handle the endpoints yourself. Tools like Monkeyman Rewrite Analyzer will help you understand how your rewrite rules end up working with existing rules. if ( ! class_exists( ‘WPSEAPIEndpoint’ ) ): class WPSEAPIEndpoint { // WordPress hooks public function __construct() { add_filter( ‘query_vars’, array ( $this, ‘add_query_vars’ ), … Read more

Retrieve data from wordpress db via input and put those result in dropdown

In the below code when you press button with the id findschoolname ajax will run. you can change the click event with on change of text box. the below script run ajax. <div class=”col-xs-4″> <div class=”zipcode”>Zip Codes <input type=”text” class=”form-control postcode” name=”postalCode” /> <input type=”button” id=”findschoolname”> </div> <div id=”replacedropwdown”> </div> </div> <script type=”text/javascript”> jQuery(document).ready(function(){ jQuery(“#findschoolname”).click(function(){ … Read more

Using get_theme_mod in php ajax form doesn’t work

You should never access directly theme files, form submissions, ajax, and even just get requests will be blocked at the server level by some security hardening measure. Ignoring that for a moment, the reason your code fails is because wordpress wasn’t bootstrapped and therefor there are no core functions available. It is actually not 100% … Read more

Ajax function is not working on WordPress

Try like this Main HTML: <form class=”home_footer” method=”post” id=”home_conct_form” action=””> <input type=”text” name=”fname” class=”txt” /> <input type=”text” name=”lname” class=”txt” /> <input type=”button” name=”home_submit” id=”home_submit” value=”Get In Touch”/> </form> Add on same page: <script> $(‘#home_submit’).click(function(){ var formData = $(“#home_conct_form”).serialize() $.ajax({ type: ‘POST’, url: ‘<?php echo home_url(“https://wordpress.stackexchange.com/”); ?>wp-admin/admin-ajax.php?action=footerFrm’, data: formData, beforeSend: function(){ $(‘.progloader’).show(); $(‘#home_submit’).hide(); }, success:function(data) { … Read more

Load image src through Ajax by ID?

You would be better off preloading all the images for the current page ahead of actually outputting them. Then you reduce the queries from n*2 (there are actually two database queries per get image call, one from the wp_posts table, the other from wp_postmeta) down to just two. $images = []; foreach ( $pages as … Read more

wp ajax execution time aborted 30 sec

there is a property timeout for ajax and you can use it. jQuery.ajax({ url: admin_ajax_url, error: function(){ // will fire when timeout is reached }, success: function( response ){ //do something }, timeout: 3000 // sets timeout to 3 seconds });

Using nonce when loading posts with AJAX

GET puts all your params on the URL like; http://example.com/thing?foo=bar&x=y For POST you could include all that information but it won’t show in the URL. http://example.com/thing Obviously if you’re thinking about security, using POST is more ideal because your params won’t show in access logs or accidentally picked up by search engines or whatever. Sending … Read more

How to use AJAX in WordPress in MYSQL query?

In WordPress it little bit complicated then default way to handle ajax form data. odify your js code like this. function ajaxSubmit(e){ // prevent the default action. e.preventDefault(); var myform= jQuery(this).serialize(); jQuery.ajax({ type:”POST”, // Get the admin ajax url which we have passed through wp_localize_script(). url: ajax_object.ajax_url, action: “submitAjaxForm”, data: myform, success:function(data){ jQuery(“.records”).html(data); } }); … Read more

Does WP_Query ‘responds’ badly to empty arguments?

I would not write it the same way, because the more cluttered a query gets, the more likely it is to return unexpected results. Here’s how I’d handle your code: $args = array(); // All your WP_Query args go here. // You don’t need to pass ‘post_status’ => ‘publish’ because that’s default // Replace all … Read more