Send email via ajax

You need to allow AJAX requests for guests too. Usually when a WordPress AJAX call returns 0, it means that there are no capabilities for the user to perform that action. Also, your debug info showed Guest. Alter your function to include the nopriv AJAX for guests: add_action(‘wp_ajax_nopriv_fahadsending_mail’, ‘fahadsending_mail’); add_action(‘wp_ajax_fahadsending_mail’, ‘fahadsending_mail’); function fahadsending_mail(){ $to = … Read more

Auto load subcategories content with ajax

Here is one way… split the AJAX function thusly: add_action( ‘wp_ajax_nopriv_load-filter’, ‘prefix_load_cat_posts’ ); add_action( ‘wp_ajax_load-filter’, ‘prefix_load_cat_posts’ ); function prefix_load_cat_posts () { $cat_id = $_POST[ ‘cat’ ]; echo load_cat_posts($cat_id); die(1); } function load_cat_posts ($cat_id) { $args = array ( ‘cat’ => $cat_id, ‘posts_per_page’ => 10 ); $posts = get_posts( $args ); global $post; ob_start (); foreach … Read more

Need help with Access-Control-Allow-Origin

I found !!! It had nothing to do with “Access-Control-Allow-Origin” was because of the API key, I entered the username and password from my dashboard help scout, I had to enter the api key for my documentation 🙂 Thanks a lot for your help 🙂

How to get setting from separate file?

Simple answer: Don’t add a separate PHP file for AJAX requests. Declare the functions that will be used in your plugin and load them via admin-ajax.php. add_action(‘wp_ajax_custom_action_name’,’custom_action_handler’); // to make AJAX action available for non-logged in users: add_action(‘wp_ajax_nopriv_custom_action_name’,’custom_action_handler’); function custom_action_handler() { global $wpdb; // optionally keep the actual functions separately // include(dirname(__FILE__).’/ajax-handler.php’); // custom_ajax_handler_process(); // … Read more

Redirect after saving form; and yet use wp_die()

Simply, you can not redirect the user from the sever in a Ajax callback. The redirect in the Ajax callback redirecta the Ajax request itself, it doesn’t redirect the user to a new location. I hope you understand what I mean. Remember that Ajax, by definition, is asynchronous. So, you need to think in another … 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

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

WP_query offset seems to be counting draft post – AJAX load more

There is a argument for posts query is post_status. It’s values are like below- $args[‘post_status’] => array( //(string / array) – use post status. Retrieves posts by Post Status, default value i’publish’. ‘publish’, // – a published post or page. ‘pending’, // – post is pending review. ‘draft’, // – a post in draft status. … Read more