Retrieving values of custom fields in Quick Edit mode

Ok, I got it, here’s the code:

function ilc_quickedit_save($post_id, $post) {
    if( $post->post_type != 'evento' ) return;
    if (isset($_POST['is_quickedit']))
        update_post_meta($post_id, 'eventdate', $_POST['eventdate']);
}

function ilc_quickedit_get() { 
    $html="<script type="text/javascript">";
    $html .= 'jQuery(document).ready(function() {';
        $html .= 'jQuery("a.editinline").live("click", function() {';

        $html .= 'var id = inlineEditPost.getId(this);';
        $html .= 'jQuery.post("' . THEME_URI . '/library/admin/admin.php",{ post_id: id, modo: "ajaxget" },';
        $html .= 'function(data){ jQuery("#eventdate").val(data); }';

    $html .= ');});});';
    $html .= '</script>';
    echo $html;
}

and the code at the beginning of the admin.php file (which is the same file where all this code is located):

if($_POST['modo'] == 'ajaxget'){
    require_once('../../../../../wp-blog-header.php');
    $post_id = $_POST['post_id'];
    echo get_post_meta($post_id, 'eventdate', true);
    return;
}

So far so good, maybe there are other ways to do it. Still need to deal with saving while in bulk editing mode. Could use a hand there too 🙂 Hope this is useful for someone.

Leave a Comment