WordPress ajax requst returns zero
Your Ajax hooked function is: function wk_check_myshop_value() { echo “asdasd”; die;} Try changing die; to die();
Your Ajax hooked function is: function wk_check_myshop_value() { echo “asdasd”; die;} Try changing die; to die();
Have you used AJAX before? Do you know what the acronym stands for? Hint: The J stands for javascript. Indeed, AJAX is usually invoked using javascript/jQuery. I believe that’s why you’re not receiving a response: you aren’t invoking an AJAX protocol or going through WordPress’s admin-ajax.php. And, why would you put a callback function in … Read more
Ok, I found out here how to procede. It was so simple I could not believe: 1) include in theme a custom script with a dependency on the favorite plugin. example: wp_enqueue_script(‘script’, get_stylesheet_directory_uri() . ‘/js/myscript.js’, ‘simple-favorite’, ‘1.0.0’, true); 2) in myscript.js just define again the function, and make it do something: function favorites_after_button_submit(favorites, post_id, site_id, … Read more
UPDATE: After I saw an error massage it’s all because unsupported operand type error. $sum += $marks; its because store wrong type of value, I change to $sum->marks;
Instead of a static class property, you could use a PHP session: class progress { public function __construct() { session_start(); } public function getTotal() { return $_SESSION[ ‘total’ ]; } public static function setTotal() { $_SESSION[ ‘total’ ] = ‘123’; } } If you’re doing more complex stuff, a session wrapper like Symfony’s might be … Read more
Finally found the problem. The action: save_post was missing from data in ajax call. This code works: <script> jQuery( document ).ready(function() { jQuery(‘input[type=button]’).on(‘click’, function() { var ajaxurl = “<?php echo admin_url(‘admin-ajax.php’); ?>”; jQuery.ajax({ type: “POST”, data: { data:jQuery(‘.event-form’).serialize(), action: ‘save_post’ }, url: ajaxurl, success: function(result) { console.log(‘data sent!’); console.log(‘sent to: ‘ + templateDir + loadUrl … Read more
You can use “mid_size” to manage number of pages to display in paginate_links() function. Please check https://developer.wordpress.org/reference/functions/paginate_links/ for pagination options. Please see example below to use mid_size. $args = array( ‘mid_size’ => 3, ‘prev_next’ => true, ‘prev_text’ => ‘« Previous’, ‘next_text’ => ‘Next »’, ); $result = paginate_links($args);
There may be browser restrictions preventing autoplaying audio, see this answer https://stackoverflow.com/questions/53058421/local-variable-audio-in-object-method-not-playing You can see this in your browser developer tools console, there will be error like this NotAllowedError: The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. If this sound … Read more
Since you use Ajax, then I would get the current comment from the REST Api, and then get the parent from that.
WordPress already provides a very nice API for admin / option page tabs. No need to reinvent the wheel on that one. Your Ajax action is “options.php” You need an action that’s linked to a PHP function that gets included by add_action( ‘wp_ajax_YOUR-ACTION-NAME*’, ‘your_php_function’); * YOUR-ACTION-NAME is the action you defined when localizing the script … Read more