I'm trying to update update_post_meta using Ajax to give value to the database when the function and toggle change I am trying. But when Ajax is running then it always makes 0 as a reaction. Code is below, please tell me where I should be reformed.
jQuery
jQuery ('Full'). Change (function () {post_id = jQuery (this) .data ('postid'); if (this is checked) {var status = "on"; else) {var status = "off";} jQuery.ajax ({Url: wpb_ajax_url, data: 'action = switch_toggle_post & amp; post_id =' + post_id + 'and condition =' + position, datatype: 'JSON', type: 'post', success: function (data) {alert ( 'Saved');}}};});
php
/ * switch toggle * / add_action ('wp_ajax_novriv_switch_toggle_post', 'switch_toggle_post'); Add_action ('wp_ajax_switch_toggle_post', 'switch_toggle_post'); Function switch_toggle_post () {add_post_meta ($ post_id, '_edit_status', $ position, true) || Update_post_meta ($ post_id, '_edit_status', $ position); }
jQuery.ajax ({url: wpb_ajax_url,
Change the URL code with the code below
url: '/wp-admin/admin-ajax.php',
No comments:
Post a Comment