New answers tagged

0

Add remove_action( 'save_post', 'my_save_post_function', 10, 3 ); inside your my_save_post_function before doing any update.


0

I think you should be able to do this: HTML: <a class="view_post_details" href="#" post_id="<?php the_ID(); ?>">View Post Details</a> JS: $(".view_post_detals").click(function () { var id_post = $(this).attr('post_id'); $.ajax({ type: 'POST', url: '<?php echo admin_url('admin-ajax.php'); ?>', data: { ...


0

Please try this and inform me what you got in the console. and sure console.log the type add_action( 'wp_ajax_comment_meta_update_vote', 'comment_meta_update_vote' ); function comment_meta_update_vote( ) { check_ajax_referer( 'upvote_nonce' ); $comment_id = $_POST['comment_id']; $vote_score = get_comment_meta($comment_id , 'vote', true); $vote_score++; $...


0

jQuery(document).ready(function($) { // Perform AJAX login on form submit $('form#login').on('submit', function(e){ $('form#login p.status').show().text(ajax_login_object.loadingmessage); $.ajax({ type: 'POST', dataType: 'json', url: ajax_login_object.ajaxurl, data: { '...


0

Eureka! So I ended up just adding in a second ajax call into the function. For some reason it's returning successful but not with a 200 response. Anyway, it's working. If anyone knows why it's returning an unknown response (besides 200 or 201) please share. Thanks! function get_posts($params) { $.ajax({ url: psc.ajax_url, data: { ...


1

If you run wp_enqueue_script() inside a shortcode, which is essentially what you're doing by calling enqueueAllMyStuff(), the script is going to be queued up to be loaded in the footer. So if your shortcode runs a script as soon as it's printed, the JavaScript file that it depends on won't be available yet, and will cause this error. The simplest solution ...


0

Add the category ID to category list items <div class="category-block" data-cid="{ID-OF-CAT}">, you will need it in the ajax request. You must also include action in the request and display received data. Here you can read more about AJAX in WP. blog.js (function($) { $(document).ready(function() { var cat_buttons = $(".category-block")...


1

I know there are ways to allow for Authentication with the Rest API, but it takes additional effort to get it to work properly. Meaning using functions like is_user_logged_in() will not work right out of the box with the Rest API, but it does with the AJAX method. So my answer would be when you need it to make requests from the Website to itself ex. when ...


1

Your code should work just fine, because there's nothing wrong with it, but... You use relative URL in it You pass loaddata.php?id1= as URL. It's relative, so it will try to find loaddata.php file in current directory. So if you're at the home page, then it will try to load that file from root directory. But if you're at some post (i.e. example.com/my-...


0

Alright, I came across another answer that's finally solved this. I had a function (in functions.php) which revoked admin access to some user types I'd created with custom privileges - that was blocking non-admin access to admin-ajax.php. Old/new function below: Old function // Revoke dashboard access add_action('admin_init', 'restrict_access_admin_panel');...


0

$post_id is never defined in any of your update loops, and this shows that a simple single loop is not enough to achive this. Since you are looping two concurrently created arrays, you would need to do something like this instead, using the index to match values: for ( $i = 0; $i < count($post_ids); $i++ ) { update_post_meta( $post_ids[$i], '...


0

The answer provided by @majick is the correct answer. I am posting this answer to show how I modified the code sample. function smsgte_admin_send() { check_ajax_referer('smsgte_nonce', 'security'); $response = admin_server_send(filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING)); echo $response; wp_die(); } The javascript code ...


2

Returning the result array will only return to the PHP function calling it, instead you actually need to output it by echoing it, and in this case because it is an array, encoding it with JSON before outputting. So return $result becomes: echo json_encode($result); exit; and then add dataType to the javascript call so it can recognize the array data: ...


0

If all you want is the content of one post: $post = get_post( $id ); $output = apply_filters( 'the_content', $post->post_content ); ob_clean(); echo $output; die();


1

You did some mistakes that I have described below: First thing you have placed jQuery Ajax code on the wrong place. On ajax callback function variable name mashup like $post_id defined and used on update time $post_ID; PHP is case sensitive so it considers 2 different variables. In some places, not closed } brackets. Here is the right code which I have ...


Top 50 recent answers are included