SHARE
TWEET

post status chagne ajax

ikamal Jun 4th, 2020 1,193 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function script_js() {
  4.     $data= [
  5.         'ajax_url'=> admin_url('admin-ajax.php')
  6.     ];
  7.  
  8.     wp_localize_script('my_script','ajax_obj', $data);
  9.  
  10.     wp_enqueue_script('my_script', get_theme_file_uri('src/script.js'),'jquery',time(),true);
  11.  
  12.  
  13. }
  14.  
  15. add_action('wp_enqueu_scripts', 'script_js');
  16. $post_id = isset($_POST['post_id']);
  17.  
  18. echo wp_json_encode($post_id);
  19.  
  20. wp_die();
  21.  
  22. function ajax_post_status_change(){
  23.  
  24. }
  25. add_action('wp_ajax_post_status_change', 'ajax_post_status_change');
  26.  
  27.  
  28.  
  29. (function ($) {
  30.  
  31.     $(document).ready(function () {
  32.  
  33.         $(".post_option a").on("click", function (e) {
  34.            
  35.             let post_id = $(this).data("post-id");
  36.  
  37.             $.ajax({
  38.               type: "POST",
  39.               url: ajax_obj.ajax_url,
  40.               data: { action: "post_status_change", post_id:post_id },
  41.               success: function (response) {
  42.                 alert(response);
  43.               },
  44.             });
  45.  
  46.             e.preventDefault();
  47.  
  48.         });
  49.     });
  50.    
  51. })(jQuery);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top