Using WordPress ‘quick_edit_custom_box’ PHP action

The quick_edit_custom_box WordPress action allows you to add custom fields to the Quick Edit mode in the admin area for each column.

Usage

add_action('quick_edit_custom_box', 'my_custom_quick_edit', 10, 3);

function my_custom_quick_edit($column_name, $post_type, $taxonomy) {
    // your custom code here
}

Parameters

  • $column_name: string – The name of the column to edit.
  • $post_type: string – The post type slug, or current screen name if this is a taxonomy list table.
  • $taxonomy: string – The taxonomy name, if any.

More information

See WordPress Developer Resources: quick_edit_custom_box

Examples

Add a custom field to the Quick Edit mode for posts

This example adds a custom field called ‘Subtitle’ to the Quick Edit mode for posts.

add_action('quick_edit_custom_box', 'add_subtitle_quick_edit', 10, 3);

function add_subtitle_quick_edit($column_name, $post_type, $taxonomy) {
    if ('post' === $post_type && 'subtitle' === $column_name) {
        echo '<fieldset class="inline-edit-col-right">
                <label>
                    <span class="title">Subtitle</span>
                    <span class="input-text-wrap">
                        <input type="text" name="subtitle" class="ptitle" value="">
                    </span>
                </label>
              </fieldset>';
    }
}

Save the custom field value

This example demonstrates how to save the custom field value entered in Quick Edit mode.

add_action('save_post', 'save_subtitle_quick_edit');

function save_subtitle_quick_edit($post_id) {
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }

    if (isset($_POST['subtitle'])) {
        update_post_meta($post_id, '_subtitle', sanitize_text_field($_POST['subtitle']));
    }
}

Display the custom field value in the column

This example shows how to display the custom field value in the ‘Subtitle’ column.

add_action('manage_posts_custom_column', 'display_subtitle_column', 10, 2);

function display_subtitle_column($column_name, $post_id) {
    if ('subtitle' === $column_name) {
        $subtitle = get_post_meta($post_id, '_subtitle', true);
        echo esc_html($subtitle);
    }
}

Add the custom field to Quick Edit mode for a custom post type

This example demonstrates how to add a custom field called ‘Price’ to the Quick Edit mode for a custom post type called ‘product’.

add_action('quick_edit_custom_box', 'add_price_quick_edit', 10, 3);

function add_price_quick_edit($column_name, $post_type, $taxonomy) {
    if ('product' === $post_type && 'price' === $column_name) {
        echo '<fieldset class="inline-edit-col-right">
                <label>
                    <span class="title">Price</span>
                    <span class="input-text-wrap">
                        <input type="text" name="price" class="ptitle" value="">
                    </span>
                </label>
              </fieldset>';
    }
}