Can I use HTTP POSTs? Is there a better alternative?

WordPress is an HTTP/PHP web application. The ordinary rules of HTTP and PHP apply, and work. WordPress itself uses $_POST and $_GET more times than I can count. If you want to pass information from one page to another– say from a form to a search handler– you have to use one or the other. … 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

WordPress File handle – fopen, fwrite not working with $.ajax or $.post Jquery

I guess the issue with this line: $path = “wp-content/themes/creation/templates/inc/log.txt”; You need to use the full path, not a relative part, while using fopen() or file_exists(). Something like this should fix your issue: $path = get_template_directory() . “/templates/inc/log.txt”; get_template_directory() will return the absolute server path, without a trailing slash.

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