WordPress Ajax Problems

You have nothing specific to do to “load” modified php code in WordPress. All files are just loaded as is at execution time (ie when the HTTP request is processed by the server). You just have to verify that your plugin is active. Your curl command is malformed. Use this instead : curl -X POST … Read more

Help with AJAX front end comment moderation

Seems to me that the only problem is that you put the full approve url in the link, in this ways when you click the link you trigger the ajax and open the page url in the link. To be more clear your link is something like: <a class=”p3-comment-moderation” href=”https://wordpress.stackexchange.com/questions/128383/admin-ajax.php?action=p3_comment_approve&comment_id=123&nonce=xxxxx” data-comment_id=”123″ data-nonce=”xxxxx”>Approve</a> thanks to the … Read more

Populating content dynamically via AJAX and Advanced Custom Fields [closed]

Here is what I ended up doing based on @gdaniel’s suggestion: AJAX call: $(‘.btn’).click(function() { $.ajax({ url:”<?php bloginfo(‘template_directory’); ?>/inc/galleries.php”, type: ‘POST’, data: {postID: ‘<?=$post->ID;?>’, galleryCategory: $(this).attr(“data-content”)}, success: function(resp) { $(‘#photos’).append(resp); } }); }); And here is my PHP file: <?php require(‘../../../../wp-load.php’); $postid = $_POST[‘postID’]; $galcat = $_POST[‘galleryCategory’]; ?> <div class=”photos” id=”$galcat”> <h1><?php echo $galcat; ?> … Read more

Call javascript function when category was added via ajax

Recently, I just have the same problem and got the solution. use ajaxSuccess event since we need to reset input when ajax is completed. filter the settings data for specific action and screen. Code: $(document).ajaxSuccess(function(e, request, settings){ var object = $.deparam(settings.data); if(object.action === ‘add-tag’ && object.screen === ‘edit-category’ && object.taxonomy === ‘category’){ //DO RESET Your … Read more

Can I fire an add_action hook inside of a function that recieves data via wp_ajax?

I guess you have a small misunderstanding here (a slight inconsistency only) add_action is to register a callback for a hook-name, you actually want to fire that hook (not register it). You can fire a hook with the do_action function. The Codex-page of the add_action function outlines both: https://developer.wordpress.org/reference/functions/add_action/ And naturally the do_action Codex-page has … Read more

Help add ajax load more button

Your div wrapper is within your while loop, and split by your if clause. This cannot work properly, since your loop will generate up to 14 divs with the id ajax. Put the opening div tag after if ( $the_query->have_posts() ) { and the closing after wp_reset_postdata(); and you should be fine. Edit Are you … Read more

Admin Ajax and HTML5 Formdata

So it turns out the only problem was the header content type. By removing request.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded; charset=UTF-8′); and just leaving it out, it worked fine. That’s also with the form action being grabbed and appended. Ajax call: var formData = new FormData(form); formData.append(‘security’, WP.nonce); formData.append(‘action’, form.getAttribute(‘action’)); u.jax.post(WP.ajax, formData, onSent); Ajax Function: u.jax.post = function(url, data, … Read more

submitting form via admin-ajax.php returns 0

You don’t set an action in your form, so nothing is executed. Add a hidden field with action to the form: <input type=”hidden” value=”submit_filter” name=”action”> Also note that this: $postid = get_the_ID(); won’t work. This is a new request, so there is no post to get the ID from. You have to pass this with … Read more