Categories
Uncategorised

How to Edit WordPress Custom Fields in Bulk

Recently, I made the decision to improve the title text of all pages of my website. The reason I did this was to make the text more enticing to click on in search results.

As an example, plain old Brown Widgets was to become the much more appealing Beginner’s Guide to Selecting the Perfect Brown Widget. Increase in traffic ensues.

One way to make this change – assuming your website runs on WordPress + Genesis – is to go into your WordPress dashboard and navigate to the editing panel for the page or post you want to edit. If you have Genesis installed, there should be a Theme SEO Settings section and a Custom Document Title field.

Whatever text you enter into this field will now appear as the page’s title in Google search results. Easy.

But what if you want to change the titles of over 50 pages? Do you…

  1. Repeat this tedious process 50 times?
  2. Pay your VA to repeat this tedious process 50 times?
  3. Give up?

The correct answer is D. Edit them in bulk! Here’s how.

Step 1: IDs

Step 1 is to have handy the WordPress IDs of all the posts or pages you want to edit. Because I’m a smart website owner, I already had these entered into a spreadsheet.

If you’re not as smart as I am, you’ll need to find the IDs by noting the post numbers in the editing URLs.

Once you’ve got all your IDs, enter them into a spreadsheet. In the column beside, write the title text you want to assign to each post.

Step 2: Writing the Code

Copy the data from your spreadsheet and paste it into TextEdit or Notepad. Ensure you are working with plain text, not rich text. You should see your IDs and titles in a kind of table, with a tab separating each ID from its corresponding title.

2540	Beginner's Guide to Selecting the Perfect Brown Widget
 2672 Beginner's Guide to Selecting the Perfect Pink Widget
 3468	Beginner's Guide to Selecting the Perfect Purple Widget
 

Now, you need to use find and replace. Copy one of the tabs and paste it into the find field. In the replace field, enter the following text:

, "_genesis_title", "
 

Your text should now look like this:

2540, "_genesis_title", "Beginner's Guide to Selecting the Perfect Brown Widget
 2672, "_genesis_title", "Beginner's Guide to Selecting the Perfect Pink Widget
 3468, "_genesis_title", "Beginner's Guide to Selecting the Perfect Purple Widget
 

Clear both the find and the replace fields completely. Then, position your cursor at the end of one of the lines (it doesn’t matter which). Click and drag to the start of the next line. You have selected the line break between the lines. Copy it, and paste into the find field.

Now, in the replace field, enter the following three lines of text exactly:

");
 INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
 VALUES (
 

Your text should now look something like this:

2540, "_genesis_title", "Beginner's Guide to Selecting the Perfect Brown Widget");
 INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
 VALUES (2672, "_genesis_title", "Beginner's Guide to Selecting the Perfect Pink Widget");
 INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
 VALUES (3468, "_genesis_title", "Beginner's Guide to Selecting the Perfect Purple Widget
 

The first and the last lines are not complete. There is code missing from the start of the first line, and from the end of the last line. Observe the pattern that’s happening on every other line, and edit the first and last lines to match the pattern. You want this:

INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
 VALUES (2540, "_genesis_title", "Beginner's Guide to Selecting the Perfect Brown Widget");
 INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
 VALUES (2672, "_genesis_title", "Beginner's Guide to Selecting the Perfect Pink Widget");
 INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
 VALUES (3468, "_genesis_title", "Beginner's Guide to Selecting the Perfect Purple Widget");
 

If your code matches the above pattern, then congratulations. You’ve constructed an SQL script. When you run your script, all your pages will update their titles instantly.

Step 3: Run Your Code

To run your script, head over to your hosting account. In your control panel, locate phpMyAdmin. When you enter phpMyAdmin, there should be a list of databases on the left. Find the database that corresponds to your WordPress website – and make sure you have the right one.

Then, click on the SQL tab at the top of the page. In the text box, enter your code and click Go. All done.

Disclaimer: The above procedure is what worked for me. I assume no responsibility if you follow it and your site breaks.