Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Possible Duplicate: How to show custom meta box on "Quick Edit" screen?

I'm trying to edit the quick edit screen on my custom post type "visitor" so that I can add some options for my end-users. My custom post type doesn't require/need a post date, password to view, publish status, or large taxonomy boxes for custom categories of visitors on it.

I've already added a custom meta box for the actual edit page, but would like to enable quick-edit support of those post meta fields while disabling the current quick-edit options.

I also found a post (linked in my possible duplicate) over on wordpress.org's forums, but not sure exactly what it does.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

I use this to add form fields to the quick edit. It's not entirely easy to do this in WP (yet) and it can be very difficult to find info on how to do it. You have to really dig through the source to find it too.

Add Form fields to Quick Edit

<?php
add_action('quick_edit_custom_box', 'quickedit_posts_custom_box', 10, 2);
add_action('admin_head-edit.php', 'quick_add_script');

function quickedit_posts_custom_box( $col, $type ) {
    if( $col != 'COLUMN_NAME' || $type != 'post' ) {
        return;
    } ?>
    <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
        <div class="inline-edit-group">
            <label class="alignleft">
                <input type="checkbox" name="yourformfield" id="yourformfield_check">
                <span class="checkbox-title">This Post Has Cake</span>
            </label>
        </div>
    </fieldset>
    <?php
}

function quick_add_script() { ?>
    <script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery('a.editinline').live('click', function() {
            var id = inlineEditPost.getId(this);
            var val = parseInt(jQuery('#inline_' + id + '_yourformfield').text());
            jQuery('#yourformfield_check').attr('checked', !!val);
        });
    });
    </script>
    <?php
}
share|improve this answer
1  
I have read this, but i dont understand; how it is possible to set the checkbox, if the post meta data is on database; get_meta_data() is only usable in php; maybe you have an hint or solution for me. Current is your example nice, but i dont understand the ID #inline_' + id + '_yourformfield; where is this; and is th ID global from WP. I have add many checkboxes and als works fine to save the data, but i dont find a solution for see the checked checkbox. Many thanks! –  bueltge Oct 10 '11 at 13:48

I'm doing a bit of tooting my own horn here, but to make editing custom meta fields in WordPress easier, I wrote a plugin called Custom Bulk/Quick Edit.

This plugin not only adds the custom meta to the Bulk and Quick Edit screens for actual editing, but also as columns to the post type listing.

Then, incase the theme or plugin in use hadn't already enabled the custom meta to the post type columns, you can use a filter to add your columns.

In your theme's functions.php file add code similar to the following.

add_filter( 'manage_post_posts_columns', 'my_manage_post_posts_columns' );
function my_manage_post_posts_columns( $columns ) {
$columns['custom_stuff'] = esc_html__( 'Custom Stuff Here' );

return $columns;
}

As an example of working with a custom post type named news-room, try the following.

add_filter( 'manage_news-room_posts_columns', 'my_manage_newsroom_posts_columns' );
function my_manage_newsroom_posts_columns( $columns ) {
$columns['wpcf-publication-author'] = esc_html__( 'Publication Author');
$columns['wpcf-newsroom-type']      = esc_html__( 'News Room Type');
$columns['_views_template']         = esc_html__( 'Content Template');

return $columns;
}

This is based upon the filter manage_${post_type}_posts_columns for the post post type.

Please note that to help further development and support, the free plugin is limited to WordPress's own built-in post types. If you're working with a custom post type, you can purchase Custom Bulk/Quick Edit Premium.

Alternately, you're welcome to extract code out of the plugin via https://github.com/michael-cannon/custom-bulkquick-edit.

share|improve this answer

Add this code in your functions.php file. This code is used for custom post type schedule. Change the post type according to your need.

// Add to our admin_init function

add_filter('manage_schedule_posts_columns', 'myown_add_post_columns');

function myown_add_post_columns($columns) {
    $columns['stime'] = 'Start Time';
   $columns['etime'] = 'End Time';
    return $columns;
}

// Add to our admin_init function

add_action('manage_schedule_posts_custom_column', 'myown_render_post_columns', 10, 2);

function myown_render_post_columns($column_name, $id) {
    switch ($column_name) {
    case 'stime':
        // show my_field
        echo get_post_meta( $id, 'stime', TRUE);

case 'etime':
        // show my_field
        $my_fieldvalue1 = get_post_meta( $id, 'etime', TRUE);
        echo $my_fieldvalue1;
    }
}

// Add to our admin_init function

add_action('quick_edit_custom_box',  'myown_add_quick_edit', 10, 2);

function myown_add_quick_edit($column_name, $post_type) {
    if ($column_name != 'stime') return;
    ?>
    <fieldset class="inline-edit-col-left">
        <div class="inline-edit-col">
            <span class="title">start time</span>
            <input id="myfield_noncename" type="hidden" name="myfield_noncename" value="" />
            <input id="myfield" type="text" name="stime" value=""/></br>
         <span class="title">End time</span>
       <input id="myfield1" type="text" name="etime" value=""/></br>
        <div id="main">
         <span class="title">Add New Session date</span></br>
       <a href="#" class="aclick">Add new</a></br></div>
        </div>
    </fieldset>
     <?php
}

// Add to our admin_init function 

add_action('save_post', 'myown_save_quick_edit_data');   

function myown_save_quick_edit_data($post_id) {     
  // verify if this is an auto save routine.         
  if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )          
      return $post_id;         
  // Check permissions     
  if ( 'stime' == $_POST['post_type'] ) {         
    if ( !current_user_can( 'edit_page', $post_id ) )             
      return $post_id;     
  } 
if ( 'etime' == $_POST['post_type'] ) {         
    if ( !current_user_can( 'edit_page', $post_id ) )             
      return $post_id;     
  } 
else {         
    if ( !current_user_can( 'edit_post', $post_id ) )         
    return $post_id;     
  }        
if(isset($_POST['tag-name']))
{
 if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
  $post = get_post($post_id);
  if ( $post->post_type == 'schedule') { // change 'post' to any cpt you want to target
    $term = get_term_by('slug', $post->post_name, 'schedule_category');
    if ( empty($term) ) {
      $add = wp_insert_term( $_POST['tag-name'], 'schedule_category', array('slug'=> $_POST['tag-name']) );
      if ( is_array($add) && isset($add['term_id']) ) {
        wp_set_object_terms($post_id, $add['term_id'], 'schedule_category', true );
      }
    }
  }
}

 // Authentication passed now we save the data   

  if (isset($_POST['stime']) && ($post->post_type != 'revision')) {
        $my_fieldvalue = esc_attr($_POST['stime']);
        if ($my_fieldvalue)
            update_post_meta( $post_id, 'stime', $my_fieldvalue);
        else
            delete_post_meta( $post_id, 'stime');
    }
    return $my_fieldvalue;
 if (isset($_POST['etime']) && ($post->post_type != 'revision')) {
        $my_fieldvalue1 = esc_attr($_POST['etime']);
        if ($my_fieldvalue1)
            update_post_meta( $post_id, 'etime', $my_fieldvalue1);
        else
            delete_post_meta( $post_id, 'etime');
    }
    return $my_fieldvalue1;
}

// Add to our admin_init function

add_action('admin_footer', 'myown_quick_edit_javascript');

function myown_quick_edit_javascript() {
    global $current_screen;
    if (($current_screen->post_type != 'schedule')) return;

    ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".aclick").one("click", function(){  
   jQuery("#main").append('<input type="text" name="tag-name" />');
});
});
function set_myfield_value(fieldValue,fieldValue1, nonce) {
        // refresh the quick menu properly
        inlineEditPost.revert();
        console.log(fieldValue);
        console.log(fieldValue1);
        jQuery('#myfield').val(fieldValue);
         jQuery('#myfield1').val(fieldValue1);
}
</script>
 <?php 
}

// Add to our admin_init function 

add_filter('post_row_actions', 'myown_expand_quick_edit_link', 10, 2);   
function myown_expand_quick_edit_link($actions, $post) {     
    global $current_screen;     
    if (($current_screen->post_type != 'schedule')) 
        return $actions;
    $nonce = wp_create_nonce( 'myfield_'.$post->ID);
    $myfielvalue = get_post_meta( $post->ID, 'stime', TRUE);
    $myfielvalue1 = get_post_meta( $post->ID, 'etime', TRUE);
    $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="';     
    $actions['inline hide-if-no-js'] .= esc_attr( __( 'Edit this item inline' ) ) . '"';
    $actions['inline hide-if-no-js'] .= " onclick=\"set_myfield_value('{$myfielvalue}','{$myfielvalue1}')\" >";
    $actions['inline hide-if-no-js'] .= __( 'Quick Edit' );
    $actions['inline hide-if-no-js'] .= '</a>';
    return $actions;
}
share|improve this answer
    
Also, please read my comments to your question about editing your posts. Your code is an unreadable mess, and it is not another person's job to clean up after you, it is your responsibility to properly edit your posts –  Pieter Goosen Jun 8 at 7:09
1  
If this is an answer, please clean it up. See How to Answer –  Pieter Goosen Jun 8 at 7:11

protected by Pieter Goosen Jun 8 at 7:10

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.