javascript - (Wordpress / AJAX): Update attachment title, description and alt from frontend -


using wordpress ajax i'm trying update attachment meta frontend. reasons json response "nan" or null. form logged users i'm not using wp_ajax_nopriv_

in functions.php

add_action('wp_ajax_update_portfolio', 'update_portfolio_function' ); function update_portfolio_function(){     $id = $_post['pid'];     $title = $_post['itemtitle'];     $description = $_post['itemdescription'];     $attachment = array(         'id' => $id,         'post_title' => $title,         'post_content' => $description     );     // update main post body     wp_update_post( $attachment );     die();      $response = array('pid'=>$id,'title'=>$title);     echo wp_send_json($response);     exit; } 

and in jquery / ajax have:

function update_info(id, itemtitle, itemdescription) {     jquery.ajax({         method: 'post',         url : ajaxurl,         datatype: "json",         data: {             'action':'update_portfolio_function',             'pid' : id,             'itemtitle' : itemtitle,             'itemdescription' : itemdescription,         },         success:function(data) {             alert(data.pid + data.title); //damn         },         error: function(errorthrown){             console.log(errorthrown);         }      });       //alert("a"); } 

as response want check if id , title have been submitted correctly. can see i'm using alert print them. values passed jquery function don't think they're received php side (or badly processed) since "nan" response on data.pid , data.title. can me?

edit request details

enter image description here

my fault. oversight here:

add_action('wp_ajax_update_portfolio', 'update_portfolio_function' ); 

should

add_action('wp_ajax_update_portfolio_function', 'update_portfolio_function' ); 

fixed.


Comments