vendredi 31 juillet 2015

Retrive the value from text input and updating/saving with ajax

I'm trying to make it work the code below but i dont know what's wrong with the meta values. I cant get the values from the input and the php is saving the variable. All i want is to update meta values by meta id (Wordpress) but i really dont understand what is wrong.

HTML

<input name="in_meta-5852-submit" id="in_meta-5852-submit" class="button updatemeta button-small buttons_span" value="Update">
<input name="in_meta[5852][value]" id="in_meta-5852-value" size="14" type="text" value=" enter numbers and letters ">

JS

    $('#in_meta-5852-submit').click(function(){
    var meta_id =  "5852";
    var values =   $('#in_meta-5852-value').val();
    var data = {

        action:             'my_action',
        post_id:            $('#post_ID').val(),
        meta_id:            meta_id,
        values:             values,
    };

    $.post(ajaxurl, data, function(response) {
        if( 0 == response ) {
        $( Saving failed);
        }
    });

PHP

add_action( 'wp_ajax_my_action', 'isave_meta' );
function isave_meta( $post ) {
$post_id = 'post';
$values = 'values';

if(isset($_POST) && isset($_POST['meta_id'])) 
{ 
update_metadata_by_mid( $post_id, absint( $_POST['meta_id'] ), $values, );
}
}

Aucun commentaire:

Enregistrer un commentaire