New answers tagged

0

For me the trick was to add wp_ajax_nopriv action. I tested the script on one browser when I was logged in WP admin, and then I tried same script in Chrome and realized that the script doesn't work. After I put wp_ajax_nopriv, everything started to work. :) add_action( 'wp_ajax_nopriv_erase_uploaded_images', 'erase_uploaded_images' ); add_action( ...


0

If you're trying to make the wordpress_logged_in_HASH cookie info available to javascript to set on the client side using javascript (and thus avoiding re-rendering the page) then I think you'll have more success re-architecting to come up with another solution. The wordpress_logged_in cookie is a httponly cookie which means you don't have access to it on ...


1

Here's how localization works. The first thing you need to do is register your script with WordPress. This pretty much tells WordPress where the script is located, what version it is, any dependants ( like jquery ), and whether it will be located in the header or footer. More importantly you need to give it a unique identifier which you'll be able to ...


2

You just have your arguments lined up wrong. Change the line to wp_enqueue_script( 'ajax-products', plugins_url( '/js/ajax.js', __FILE__ ), array('jquery'), '1.2', false ); You can use plugins_url() with the second parameter of __FILE__ to get the directory of the specific pluign, and in the first argument you pass the relative location of your script. ...


0

Here's the fix... Change the line in \inc\woocommerce\template-tags-categories.php which reads: $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button ajax_add_to_cart' : '', to: $product->is_purchasable() && $product->is_in_stock() && $product->is_type( 'simple' ) ? 'add_to_cart_button ...


1

Alright, there's a few things that isn't standardized WordPress so I've put together a minimal script which I'll explain piece by piece. Hopefully clear things up for you by the time you get to the end. HTML Form Below is a very simple HTML form. We're going to use javascript to listen for submission and stop it from actually refreshing the page but that ...


0

Switch to full SSL for everything. Seriously, it's way easier than dealing with mixed content.


0

The plugin you are using is quite old. I use this one without issues: https://wordpress.org/plugins/wp-force-ssl/


0

You'll want to make sure you're loading the form with AJAX enabled. I'm assuming that the the form is actually refreshing the entire page (hence the popup closing). If you enable AJAX, only the form should be refreshed and the popup's visibility should not be impacted.


0

This is done by Mosaic Generator wordpress plugin. Use code between the end of "header" and "content" or in another place of your templates for example: <?php mosaic_generator(size, height, width, genrating_type, border_size, color, use_link);?> OR You can use shortcode for example: [mosaic_generator s=20, h=3, w=3, gt='div', b=1, c='FFFFFF', ...


0

There are two hooks for adding AJAX handlers, you're missing the one for non-logged in visitors. You need: add_action( 'wp_ajax_nopriv_adClickCounter', 'adClickCounter_ajax' ); ... in addition to the add_action call you currently have. Note the extra nopriv_ in the tag.


0

I was missing a crucial line in my AJAX query. Without this option, the call fails, and the pages refreshes. processData: false,


3

Try using preventDefault(), it's a jQuery function for preventing default actions called by the browser. First you should call an event handler by firing up your submitter. You can do this as follow: $('#my_upload_form').submit(function (event) { After catching a submit and giving an event with it, you should prevent the default refresh of a browser: ...


0

Also the way you are calling your function is incorrect : <div><?php echo $get_number_of_promos(); ?></div> You are calling a function (get_number_of_promos) as a string ($). It should be : <div><?php echo get_number_of_promos(); ?></div>


1

This line in functions.php is your problem: $cat_id = get_post_meta($_REQUEST['cat']); I think you are misunderstanding the purpose of the get_post_meta() function. It is designed to get metadata for a WordPress Post, not data from a POST request to the site. The first parameter of the get_post_meta() function is the $post_id, but since you are passing ...


1

There is an error in your src; <img src="http://example.com//wp-admin/admin-ajax.php?action=random_banner"> Try this one: <img src="http://example.com/wp-admin/admin-ajax.php?action=random_banner"> or <img src="<?php echo admin_url( 'admin-ajax.php?action=random_banner' ); ?>"> You can also use a query to get a random image. ...


0

Personally, I like to do something like this as Error Reporting. When something goes wrong - in the PHP function - set an Error Header that will return back to your JQuery along with a string message: header( 'HTTP/1.1 400 Empty Attachment' ); echo 'Could Not Upload File.'; exit; To classify this as an error header you need HTTP/1.1 400 but after that you ...


0

It's possible to capture the $post_id using a combination of wp_get_referer() and url_to_postid() then reset the $post using setup_postdata. That should work easy enough for the front-end. But on the admin side we'll need to pull the query with parse_url and grab the ID using parse_str. For good measure we should double check if we're editing a post by ...


0

From my experience if an ajax call in wordpress returns 0, it means that ajax can't find the related php function, so check three times that the function you point to in 'add_action', function name and the action of your form do match. I usually include an action attribute in the ajaxSubmit options as well, maybe it solves your problem. Just add action : ...


0

This was wrong: Replace this: add_action( 'wp_ajax_nopriv_lateral_fluid', 'my_lateral_fluid' ); add_action( 'wp_ajax_lateral_fluid', 'my_lateral_fluid' ); With this: add_action( 'wp_ajax_nopriv_my_lateral_fluid', 'my_lateral_fluid' ); add_action( 'wp_ajax_my_lateral_fluid', 'my_lateral_fluid' );


0

The codex says here that The wp_ajax_ hook follows the format "wp_ajax_$youraction", where $youraction is your AJAX request's 'action' property. I suppose in your js file you should go for: data: { action: 'lateral_fluid', // the $action to run }


0

Good afternoon, I managed to sort this out. I have amended my functions.php to the following. function mcPaySubmit(){ global $wpdb; include('paygate.php'); $last = wp_get_recent_posts(array('numberposts' => '1', 'post_type' => 'post', 'post_status' => 'pending', 'author' => $user_id)); $purchase_post_id = $last['0']['ID']; $purchase_days = ...


0

To clarify your doubt you localized variable will contains the same values until it is overriden. In your case EMX.ajaxurl will be available throught the script. Ajax not happening at your intended event might be due to not executing the ajax function but definetly not due to EMX.ajaxurl. EMX.ajaxurl will contain the ajax url. EMX.ajaxurl can be used for ...


0

When working with AJAX and Forms in WordPress I like to code in the ajax action to the form so serialize works out of the box. Actually I wrote an article on this last year: https://webdevstudios.com/2015/02/12/handling-ajax-in-wordpress/ But, you're here for answers, not a blog article, so here's the brief part of it. You have three parts here, first is ...



Top 50 recent answers are included