0

I am following this https://gist.github.com/michael-cannon/5820098 to update bulk values but its not working. I tried to debug each and every step but can't get the exact error.

I have the following codes of js:

$( '#bulk_edit' ).on( 'click', function() {
    // define the bulk edit row
    var $bulk_row = $( '#bulk-edit' );

    // get the selected post ids that are being edited
    var $post_ids = new Array();
    var $langs = {};

    $bulk_row.find( '#bulk-titles' ).children().each( function() {
        $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) );
    });

    // get the data
    $('.uni_lng-checklist li input[type="checkbox"]:checked', $bulk_row).each(function(){
        var k = $(this).attr('name').replace('wpcf[languages-kerk][', '').replace(']', '');
        var v = $(this).attr('value');
        $langs[k] = v;
    });


    // save the data
    $.ajax({
        url: ajaxurl, // this is a variable that WordPress has already defined for us
        type: 'POST',
        async: false,
        cache: false,
        data: {
            action: 'save_bulk_custom_language', // this is the name of our WP AJAX function that we'll set up next
            post_ids: $post_ids, // and these are the 2 parameters we're passing to our function
            wpcf: $langs,
        }
    });

});

and the ajax action hook is :

add_action( 'wp_ajax_save_bulk_custom_language', 'uni_save_bulk_custom_language' );
function uni_save_bulk_custom_language() {

  $post_ids = ( ! empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : array();
  $languages = ( ! empty( $_POST['wpcf'] ) ) ? $_POST['wpcf'] : null;

  if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
    foreach ( $post_ids as $post_id ) {
        update_post_meta( $post_id, 'wpcf-languages-kerk', $languages );
    }
  }

  die();
}

I tried to check the update_post_meta function which return true every time, means its updating the value. but when i try to check in the database or when the page refresh on bulk update its displaying blank even in the database. Can anyone please help me to detect the exact problem?

  • Does $languages hold expected value if you dump it? – Rarst Jul 11 '14 at 13:09
  • @Rarst yes it has, and even if i do if(update_post_meta( $post_id, 'wpcf-languages-kerk', $languages )) then it return true, and i tried to check serialize($languages) then it hold the same value that i want after bulk update. But i don't know what happened after page refresh. :( – jogesh_pi Jul 11 '14 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.