Ajax is not working in a loop

Your code has var getid = $(‘#my-categorychecklist input:checked’).last().val(); see the .last(), that’s why you’re only getting the last item Also, why do you have the same thing in getid and matchid? You need to store the selected categories in an array and loop through them, try something like: var selected_cats = $(‘#my-categorychecklist input:checked’).map(function() { return … Read more

Get image url using image id

You can use REST API to retrieve media item. Just send GET request to this address (change example.com to your site): http://example.com/wp-json/wp/v2/media/<id> If you pass correct ID, then you’ll get all info regarding that media file. For example I get something like this for one of my image files: { “id”: 546, “date”: “2019-01-23T11:22:15”, “date_gmt”: … Read more

AJAX on Front-End Button Click not working – Custom Plugin

Ok, so it’s pretty easy error – just a typo 😉 You use this line to localize your script: wp_localize_script( ‘ajax-script’, ‘my_foobar_client’, array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ ), ‘we_value’ => 1234 ) ); So you use ajax_url field to store url to admin-ajax.php But you use this line in your js file: my_foobar_client.ajaxurl, and there … Read more

WordPress ajax-action how to return content

OK, so you misunderstood it a little bit, I guess… You do the first part correctly. So yes – AJAX requests should be sent to wp-admin/admin-ajax.php and the should have action param set in the request (either as a POST or as a GET). But then, you do it wrong. You register your action with … Read more

AJAX button action in foreach

This is happening because you have click event firing on ID jQuery(‘#przyciskUlubione’).click(function() { The ID is always unique, there should never be more than one same ID in the HTML. You can achieve this using class. Assign the same class to all the buttons. Change your selector to class: jQuery(‘.przyciskUlubione’).click(function() { add value attribute or … Read more

WordPress AJAX return 0 – My case

You function name and your ajax action callback name should be same. add_action(‘wp_ajax_pdfAction’,’pdfAction_callback’); add_action(‘wp_ajax_nopriv_pdfAction’,’pdfAction_callback’); function pdfAction_callback(){ $post = $_POST[‘pdfAction’]; echo “something”; wp_die(); } Please update your php code with the above. Currently, your php function is not getting executed. Update: The Ajax Script, $(document).on(‘click’, “#generate-pdf”, function(){ var price1 = $(“#price1”).val(); var price2 = $(“#price2”).val(); $.ajax({ … Read more