Blog

2 easy ways to bulk edit custom fields in WordPress 

bulk edit custom fields
Table of Contents

WordPress custom field is a type of metadata that allows you to publish your desired information along with each post in WordPress. Each custom field contains a name (key) and data (value) that you need to edit regularly. If you are managing several sites in which you upload several posts, bulk editing custom fields in WordPress is definitely one of your essential needs. 

Unfortunately, there is no tool for bulk editing advanced custom fields in the default editor of WordPress. So, to make any changes, you have to enter the posts edit page and apply your changes individually.

But to save your time and effort, you can get help from the two methods we introduce in this article for WordPress bulk edit custom fields. In the first method, we will show you how to bulk edit advanced custom fields programmatically, and in the second method, through the WordPress posts/pages bulk edit plugin.

Bulk edit custom fields in WordPress programmatically

If you are familiar with coding, you don’t need to install any plugins for WordPress quick edit custom fields, and you can do this with just a few pieces of code.

Of course, before doing this, it is better to make a backup of your site so that you can restore your data to the original data in case of a malfunction.

Now, suppose we want to add the “Price” and “Featured product” columns to the post table, as shown in the image below. So that we can bulk edit them by the default editor of WordPress:

bulk edit custom fields programmatically in WordPress

To do this, you need to add the three below codes to the functions.php file of your current theme or create a child theme for that.

First code: Create a column for every custom field 

In the first step, you have to add custom field columns to the post table. The below code is written to add Price and Featured products to the table. It is worth mentioning that you can replace these two words in the code below with the name of your custom fields to see their columns in the post table.

// add new columns
add_filter( 'manage_post_posts_columns', 'ithemeland_price_and_featured_columns' );
//The above hook will add columns only for the default 'post' post type for CPT:
// manage_{POST TYPE NAME}_posts_columns
function ithemeland_price_and_featured_columns( $column_array ) {
$column_array[ 'price' ] = 'Price';
$column_array[ 'featured' ] = 'Featured product';
//The above code will add columns at the end of the array
//If you want columns to be added in another order, use array_slice()

return $column_array;
}
// Populate our new columns with data
add_action( 'manage_posts_custom_column', 'ithemeland_populate_both_columns', 10, 2 );
function ithemeland_populate_both_columns( $column_name, $post_id ) {

//If you have to populate more than one column, use switch()
switch( $column_name ) {
case 'price': {
$price = get_post_meta( $post_id, 'product_price', true );
echo $price ? '$'.$price : '';
break;
}
case 'featured': {
echo get_post_meta( $post_id, 'product_featured', true );
break;
}
}

}

You can also play with CSS to make columns wider or thinner.

If you don’t want to overload your admin pages with custom field columns, it is easily possible to hide them in the “Screen Options”. Please note that by hiding those columns, you can not use quick edit functionality anyway.

Second code: Make the fields appear in bulk edit

In the second step, you should use the bulk_edit_custom_box action hook to make the added custom fields appear in the bulk edit. Please note that the action hook is fired for every column, so we add an opening <fieldset> tag when displaying the first field in a group and a closing </fieldset> tag when displaying the last one.

<?php
// bulk_edit_custom_box allows to add HTML in Quick Edit
add_action( 'bulk_edit_custom_box', 'ithemeland_quick_edit_fields', 10, 2 );
function ithemeland_quick_edit_fields( $column_name, $post_type ) {
switch( $column_name ) {
case 'price': {
?>
<fieldset class="inline-edit-col-left">
<div class="inline-edit-col">
<label>
<span class="title">Price</span>
<input type="text" name="price">
</label>
</div>
<?php
break;
}
case 'featured': {
?>
<div class="inline-edit-col">
<label>
<input type="checkbox" name="featured"> Featured product
</label>
</div>
</fieldset>
<?php
break;
}
}
}

By adding this code, you can bulk edit custom fields in WordPress.

Third code: Save WordPress custom fields

As the last step, you need to use the save_post action hook, which is a nonce check, and get form values from $_REQUEST, not $_POST. Please note that in this nonce check, we are using bulk-posts action. If you want to use this code for pages, it must change to bulk-pages.

add_action( 'save_post', 'ithemeland_bulk_edit_save' );
function ithemeland_bulk_edit_save( $post_id ){
// check bulk edit nonce
if ( ! wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'bulk-posts' ) ) {
return;
}
// update the price
$price = ! empty( $_REQUEST[ 'price' ] ) ? absint( $_REQUEST[ 'price' ] ) : 0;
update_post_meta( $post_id, 'product_price', $price );
// update checkbox
$featured = ( isset( $_REQUEST[ 'featured' ] ) && 'on' == $_REQUEST[ 'featured' ] ) ? 'yes' : 'no';
update_post_meta( $post_id, 'product_featured', $featured );

It is also possible to add custom fields to quick edit by using the below action hook:

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

Although you can successfully add as many custom fields as you need to the quick edit or bulk edit of WordPress by adding the above codes, repeating these steps need a lot of time and effort. 

In addition, you just have access to bulk edit custom fields in the default editor of WordPress, which is really a nightmare for bloggers. This editor has many limitations because there are neither enough filtering options nor editing fields to meet the requirements of site managers. 

Despite that, if you make any mistake in adding codes to the WordPress theme, it may be a complete disaster and ruin your website.

For all these reasons, it makes sense if you use the WordPress post bulk edit plugin. 

WordPress quick edit custom fields by posts bulk edit plugin

The WordPress posts/pages bulk edit plugin allows you to bulk edit all WordPress post fields such as categories, tags, titles, and most importantly, custom fields just with one click. If you want to easily filter your custom posts and, pages and quickly bulk edit them, you need to use this plugin in the following four simple steps:

Step 1: Install the WordPress bulk edit posts plugin 

For the first step, you need to download and install the WordPress bulk edit posts plugin on your website. Then you can see the iT bulk editing menu in the WordPress dashboard. Now, by clicking on the WP Posts menu, you have access to the main page of this plugin.

select WP Posts menu in Bulk Editing WordPress

Step 2: Add WordPress advanced custom fields to the plugin

In the plugin’s main page you can see a list of all WordPress posts in a table with a useful toolbar on the top of the table. To bulk edit custom fields in WordPress, you have to add them to the plugin manually or automatically in the Meta Fields form. 

To open this form, press the Meta Fields button on the toolbar.

add advanced custom fields to WordPress plugin

In this form, you can find two separate sections: 

  • The first section allows you to manually add the WordPress custom fields to the plugin and have access to them in the filter form and bulk edit form.
  • The second section is designed to let you automatically add all custom fields of one post to the plugin.

Let’s review both methods, briefly.

Add WordPress custom fields to the plugin, manually

Try the below steps in the Manually section to add any custom field to the WordPress posts bulk edit plugin, individually:

  1. Write the Custom Field name in the textbox.
  2. Press the + button to see the custom field settings in the right panel.
add manually custom fields to WordPress plugin

For example, we have added Source and Reading Time custom fields by repeating the above two steps. Now, it is time to specify the type of custom fields in the right panel. To do this, the following steps are required: 

  1. Set a name for the Custom Field.
  2. Choose the custom field type from the dropdown list, including:
  • Textinput
  • Textarea
  • Checkbox
  • Radio
  • Array
  • Calendar
  • Email
  • Password
  • URL
  • Image
  • File
  • Editor
  • Select
  1. After selecting the custom field type, you can select the type of value that can be assigned to it. The plugin will automatically show you some options related to the custom field type, and you need to choose one of them from the list.
select custom field type in meta field section

For example, when we added the Reading Time as the custom field and set its type to Textinput, two options were available for the value type: Text and Number. As the Reading Time is specified by a number, we chose the same from the list.

  1. Finally, you can customize the order of displaying custom fields in the table or remove them by clicking on the appropriate icons.

Add WordPress custom field to the plugin, automatically

To make the process of importing WordPress custom fields to our plugin faster, we designed to add custom fields automatically from the post. In this section, you can easily insert the ID of any post in the textbox, then press + to see a list of all custom fields assigned to that post in the right panel.

add automatically custom field to WordPress plugin

By repeating the steps mentioned above, it is possible to set the type and value of each custom field.

After adding the meta fields in this form, you have access to them in the post table, filter form, and bulk edit form.

show source and reading time columns in WordPress plugin

Now, let’s see how this plugin simplifies WordPress bulk edit custom fields. 

Step 3: Filter WordPress custom fields 

The next step for WordPress to quick edit custom fields is filtering the required posts. For this purpose, you can: 

  • Open the filter form by pressing the Filter icon on the Toolbar.
filter custom fields in WordPress
  • Open one of the filtering tabs, including:
    • General
    • Categories/Tags/Taxonomies
    • Date & Type
    • Custom Fields

As we mentioned before, you can see all metadata you have imported to the plugin in the custom fields tab and filter your posts based on.

select custom fields tab in filter form section
  • Set filtering options and press Get Posts.

Step 4: WordPress bulk edit custom fields

After filtering the posts, a list of your desired posts is displayed in the table and you can follow the below instructions to quickly bulk edit custom fields in WordPress:

  • Mark some posts in the table.
  • Open the Bulk Edit form by pressing the bulk edit icon on the Toolbar.
bulk edit custom fields in WordPress
  • Go to the Custom Field tab and find the meta field you want to bulk edit.
select operator to reading time field in filter form section
  • Select one of the Operators from the first combo box. The list of Operators is automatically changed based on the Custom Field Type. For example, to bulk edit Reading Time, which was set to Textinput type, the following Operators are available:
    • New
    • Append
    • Prepend
    • Delete
    • Replace
    • Clear
  • Insert value in the second box.
  • Choose one of the variables from the third list if needed. The available variable by default is:
    • Title
    • ID
    • Menu Order
    • Parent ID
    • Parent Title
select variable to reading time field in filter form section
  • Press the Do Bulk Edit button to make changes in the custom fields of selected posts.

To clear it for you, let’s review some examples.

WordPress post bulk edit

Example: Add (min) at the end of reading time in food or lifestyle posts 

To fulfill the purpose of this example, try to:

  • Open Filter Form and go to Categories tab.
  • Choose OR from the Operator list of Categories field and select Food and Lifestyle from the list of categories.
select categories filed in filter form section
  • Press Get posts to see a list of Food or Lifestyle posts in the table.
  • Mark all or some of the posts in the table.
show categories column in WordPress plugin
  • Open the Bulk Edit form and go to the Custom Fields tab.
select custom fields tab in bulk edit form section
  • Find the Reading Time field, choose Append from the Operator List, Write (min) in the Textbox. 
  • Press Do Bulk Edit. 

As you can see in the below picture, the desired changes were made on the selected posts:

show reading time column in WordPress plugin

You can find more examples about WordPress bulk edit custom fields with our plugin, here.

Extra features of WordPress posts/pages bulk edit plugin

In addition to using the bulk edit form in the WordPress bulk edit posts plugin, you can change the value of multiple custom fields by using Inline Edit and Bind Edit. These methods allow you to make your desired changes directly in the table without the need to open a bulk edit form.

Let’s review both methods by giving some examples.

WordPress quick edit custom fields by inline editing

To use the inline edit method, first you have to add the custom fields columns to the table by opening the Column Manager form. The Column Manager icon is designed in the Toolbar as illustrated below:

select column manager icon in WordPress plugin

In this form, you can find the Custom Fields section and mark any meta fields that you want to see in the table:

select custom fields columns in column profiles section

By pressing Get Columns, the marked WordPress custom fields are displayed in the table.

To inline edit custom fields in WordPress, click on the custom field cell in front of your desired post and edit it directly in the table.

inline edit custom fields in WordPress

WordPress bulk edit custom fields by bind edit

To bind edit the meta fields, first add the custom fields you need in the table as we described before. Then: 

  • Mark the posts that you want to change their value in the table.
mark ID to bulk edit custom fields by bind edit in WordPress plugin
  • Click on the Bind Edit option in the Toolbar.
  • Press one of the custom field cells of the marked posts and make the changes you want, then press Enter on the Keyboard. 
bind edit custom field cells in WordPress plugin
  • After a few seconds, the plugin will automatically change the value of other cells.
automatically change value of other cells in WordPress plugin

Conclusion

If you want to create dynamic websites and use the full power of WordPress as a content management system, using custom fields is essential. But when you publish a large number of posts with multiple custom fields, bulk editing them becomes very difficult and time-consuming. Using the WordPress posts/pages bulk edit plugin helps you to bulk edit all fields and custom fields in WordPress as quickly as possible.

WordPress post bulk edit

Leave a Reply

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

Shopping cart
Sign in

No account yet?

We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies.

Start typing to see products you are looking for.