Posted in WordPress

Add custom field to quick edit screen in WordPress

Add custom field to quick edit screen in WordPress Posted on January 2, 20163 Comments

When you create custom fields in WordPress, it’s easy to put them in meta box and you can update their data via HTML inputs. But in some cases, you want to edit them in quick edit screen, how can you do that?. In this article, I will show you how to add your custom fields to quick edit screen.

In my example, the name of custom field is headline_news, it can verify to show a post in Headline area and we use checkbox input for it. Now, let’s do it.

Step 1: Add custom field to post edit screen in management page.

Notice: You have to do this step if you want to use your custom field in quick edit screen.

If your custom field is in a custom post type, change the name of the filter to manage_edit-{your-custom-post-type-name}_columns. After you’ve done this step, your screen will look like these images below.

Screenshot_1

Screenshot_2

Step 2: Receive meta-data from database and set it to new column.

Don’t forget to use manage_{your-custom-post-type-name}_posts_custom_column instead of manage_posts_custom_column if you use custom post type.

Screenshot_3

Step 3: Add Headline news checkbox to quick edit screen.

After this step, you can see your checkbox in quick edit screen like this:

Screenshot_4

Step 4: Save custom field to database.

Step 5: By default, your checkbox can’t get its value, that’s why we have to write a javascript function to set value for it.

In this example, I wrote a function named checked_headline_news, the function gets value and set it to checkbox.

Step 6: Receive meta-data value of custom field and pass it to javascript function when user clicks expand quick edit link.

That’s all what we need to add custom field to quick edit screen in WordPress, thanks for your reading!

3 thoughts on “Add custom field to quick edit screen in WordPress

  1. Great tutorial, it helped a lot. Many thanks! There are jaust a few tutorials on this online, and this one is the most straightforward.

  2. Wow, I’ve used WordPress for a long time but never learned how to do this. This is amazing.

    If i want to add another custom field, do I need to duplicate all these functions?

    1. No, you don’t have to duplicate functions, only add new lines for your new field, for example:
      Step 1: $columns[‘another_field’] = ‘Another field’;
      Step 2: $another_field = get_post_meta( $post_id, ‘another_field’, true );
      ..

Leave a Reply

Your email address will not be published. Required fields are marked *