Advertisement
Skip to content

WordPress custom fields after import: 4 checks before you trust the data

By Updated 10 min read

On this page (10 sections)
  1. The short version
  2. Why do WordPress custom fields come out messed up after import?
  3. Check 1: do the field counts match?
  4. Check 2: do the field keys and reference pairs match?
  5. Check 3: do sample values match the source?
  6. Check 4: does each field have the expected type?
  7. How do you fix messed up custom fields after import?
  8. How do you verify fields before publishing?
  9. How can you prevent the problem on the next migration?
  10. Questions people still ask

In short: In WordPress, messed up custom fields after import usually come from missing rows, changed keys, damaged values or wrong data types. Run four checks: compare counts, compare keys, inspect values and test types. Repair the affected fields with a controlled field-only re-import or narrow database change. Readers using another platform can apply the same checks to its custom-field table.

Counts catch lost fields, key comparisons catch renamed fields and type tests catch hidden damage.

At a glance
First checkfield row count per post
Second checkfield names and references
Common breakserialized array damage
Safe fixfield-only re-import
Rollback toolhost snapshot or SQL export
Verify onthe rendered page

The short version

  • Count custom-field rows per post in the source and destination.
  • Compare distinct field names and check plugin reference rows.
  • Inspect sample values for truncation, encoding and ID errors.
  • Test numbers, dates, arrays and serialized values against their expected formats.
  • Verify repaired fields on rendered WordPress pages.

Why do WordPress custom fields come out messed up after import?

The posts imported fine. Titles, body text and dates are present. Then a template or plugin shows an empty field, wrong value or broken formatting.

WordPress usually stores these rows in wp_postmeta. Each row links a post ID with a field name and value. Your table prefix may differ.

A field-type mismatch is one common cause. A number or array can arrive as plain text. A name mismatch is another. The source may use price_usd, while the destination expects price.

Serialized data can also break. PHP serialized values contain byte counts. A changed string length can make the whole value unreadable. The other half of this decision is ai-assisted content planning.

Encoding damage changes accented characters. ID remapping can also make a related-post field point to the wrong post.

Plugin fields often use reference pairs. A visible key such as price may have a hidden _price row. Advanced Custom Fields, often called ACF, uses this pattern to identify the field definition. An import that keeps one row but drops its pair can make values appear missing.

  • Field-type mismatch: the value has the wrong format.
  • Name mismatch: data exists under another key.
  • Serialization damage: arrays become unusable strings.
  • Encoding damage: characters change during transfer.
  • ID remapping: related fields point to wrong posts.
  • Reference-pair damage: an ACF or plugin value loses its hidden definition key.
  • Duplicate rows: several values exist for one post and key.

Check 1: do the field counts match?

laptop showing a spreadsheet of WordPress post IDs and field names
laptop showing a spreadsheet of WordPress post IDs and field names

Use the same query on both databases. Replace wp_ with your real table prefix. Run it with proper database access and save each result. We cover web page loading slow on shared hosting in its own article.

Run: SELECT post_id, COUNT(*) AS meta_count FROM wp_postmeta GROUP BY post_id; Compare matching posts. A lower destination count shows possible field loss, but equal counts do not prove values are correct.

Check duplicate rows too: SELECT post_id, meta_key, COUNT(*) AS c FROM wp_postmeta GROUP BY post_id, meta_key HAVING c > 1; Multiple rows can make a template read the wrong value. Inspect each result, keep the intended row, and remove duplicates only after confirming the source value.

Count gaps point to missing rows. Duplicate counts point to conflicting rows. Use the next check to find missing or changed keys. We cover preserving post layout during migration in its own article.

What the row comparison tells you
ResultLikely causeNext check
Destination has fewer rowsImporter skipped fieldsCompare field keys
Same rows, wrong valuesValue or encoding damageInspect samples
Duplicate post and key rowsRepeated import or merge conflictCompare values and remove extras
More destination rowsDuplicate or unexpected fieldsCheck keys and import logs

Check 2: do the field keys and reference pairs match?

List the keys separately: SELECT DISTINCT meta_key FROM wp_postmeta ORDER BY meta_key; Export the source and destination lists as CSV files.

A spreadsheet gives you a quick diff. Put the source list in column A and the destination list in column B. In C2, enter =IF(COUNTIF($B:$B,A2)=0,"missing in destination","present"). Copy the formula down. Reverse the columns to find destination-only keys.

For a SQL-side comparison, load each list into temporary tables with one meta_key column. Then run: SELECT s.meta_key FROM source_keys s LEFT JOIN destination_keys d ON d.meta_key=s.meta_key WHERE d.meta_key IS NULL; This returns source keys missing from the destination. We cover jwt authentication fails after importing wordpress users in its own article.

Check ACF and plugin pairs with a query such as: SELECT p.post_id FROM wp_postmeta p LEFT JOIN wp_postmeta r ON r.post_id=p.post_id AND r.meta_key='_price' WHERE p.meta_key='price' AND r.post_id IS NULL; Replace price with the visible key. Replace _price with its reference key. Results need review because not every plugin uses the same pairing.

A missing key can mean a mapping error, skipped field or renamed field. A value under the wrong key can look empty in the editor or template.

Key comparison results
ResultLikely causeAction
Source key missingMapping or import rule skipped itCheck importer field mapping
Destination-only keyRename, duplicate or plugin fieldInspect the import log
Visible key without reference keyACF or plugin pairing damageRestore the matching reference row
Same keys, different valuesValue or type damageRun checks three and four

Check 3: do sample values match the source?

two database query windows showing WordPress postmeta counts
two database query windows showing WordPress postmeta counts

Counts prove rows exist. They do not prove values are right. Pick ten random posts and five important posts. Compare each critical field on both sites. It helps to understand prevent timing drift during editor switches before going further.

Look for long values ending at the same character limit. This can indicate truncation. Run: SELECT post_id, meta_key, CHAR_LENGTH(meta_value) AS chars FROM wp_postmeta WHERE CHAR_LENGTH(meta_value) >= 255 ORDER BY chars DESC LIMIT 100; Treat 255 as a lead. Check the actual importer and column limits before changing data.

Check numeric-looking values, empty strings, changed accents, curly quotes and related IDs. A value such as 19.99 may arrive as text. Text is not always wrong, but the template must expect it.

Search for serialized-looking values with: SELECT meta_id, post_id, meta_key, LEFT(meta_value, 20) AS start_text, RIGHT(meta_value, 20) AS end_text FROM wp_postmeta WHERE meta_value REGEXP '^(a|O|s|i|b|d|N):' ORDER BY meta_id LIMIT 100; SQL only flags candidates. A PHP decoder must confirm the structure.

A value ending inside a quoted string needs closer testing. Compare suspicious rows with the source before editing them.

Check 4: does each field have the expected type?

Test each important field against the format its template or plugin expects. Confirm those rules in the field definition and importer settings.

To find non-numeric prices, run: SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE meta_key = 'price_usd' AND meta_value <> '' AND meta_value NOT REGEXP '^[0-9]+(\\.[0-9]+)?$' LIMIT 100; Change the key and pattern for negative numbers or other formats.

For ISO dates, run: SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = 'event_date' AND meta_value <> '' AND STR_TO_DATE(meta_value, '%Y-%m-%d') IS NULL LIMIT 100; Compare each result with the source. A valid date in another format will appear here.

For serialized values, database matching is only a screen. PHP must validate byte counts. Decode returned values with a trusted PHP test, or re-import them from the source.

WordPress keys beginning with an underscore often belong to plugins. Compare prefixes, visible keys and reference keys on both sites.

How do you fix messed up custom fields after import?

spreadsheet comparing source and destination WordPress meta keys
spreadsheet comparing source and destination WordPress meta keys

Use a staging copy when you have one. If staging is unavailable, ask the host for a restorable snapshot or use the backup supplied by your backup plugin. Test there before touching production.

Export the affected table before changing it. WP-CLI can create an export: wp db export wp-postmeta-before-fix.sql --tables=wp_postmeta. A direct export also works: mysqldump -u DB_USER -p DB_NAME wp_postmeta > wp-postmeta-before-fix.sql. Add --no-create-info for rows only.

Create a temporary backup table if your database has space: CREATE TABLE wp_postmeta_backup_20250308 AS SELECT * FROM wp_postmeta; Use a unique name and record its creation time.

For a simple key rename, test inside a transaction: START TRANSACTION; UPDATE wp_postmeta SET meta_key = 'price_usd' WHERE meta_key = 'price'; SELECT ROW_COUNT(); ROLLBACK; Review the affected rows. Use COMMIT only after the test passes. Transactions do not replace a backup.

Limit updates by post IDs or import-batch markers where possible. For related IDs, create an old-to-new map. Read each old ID, find its new ID, and write the mapped value. Do not infer relationships from post titles.

Re-import broken serialized fields from the source. Do not rebuild damaged strings by hand. Use the importer’s field-only mode and a stable mapped ID or slug. Turn off overwriting later edits where the importer allows it.

For serializer-safe replacements, run wp search-replace --dry-run first. Limit the search to the intended tables and columns. Review the dry-run count before running the actual command.

Restore with mysql -u DB_USER -p DB_NAME < wp-postmeta-before-fix.sql only when the export matches the database you need to restore. A host snapshot or plugin backup may be safer when related tables must return to one point in time.

  1. Clone the site or database to staging, or obtain a host snapshot or plugin backup.
  2. Export the affected wp_postmeta rows before changing them.
  3. Compare counts, keys, reference pairs, values and types.
  4. Test the narrow repair and inspect affected rows.
  5. Apply only the repair that passed testing.
  6. Run the checks again and verify rendered pages.

How do you verify fields before publishing?

A database value can be correct while the page remains wrong. Templates cache output, plugins filter values and field keys can differ from template code.

Compare repaired counts and key lists with the source. Recheck sampled values and run type queries for every important field.

Open at least one post for each template type. Test the rendered page, not just the editor. Clear the relevant cache before judging the result.

Run the structured-data validator used by your theme or SEO setup. Missing price, rating or review fields can affect markup even when the page looks correct.

Keep the source read-only until the destination passes. If a template test fails, repair only the affected field and test again.

How can you prevent the problem on the next migration?

Rehearse the import with five difficult posts. Include arrays, long text, dates, related IDs and fields with underscores. Run all four checks on the rehearsal copy.

Save the old-to-new ID map. Document every source key, destination key and ACF or plugin reference pair. Test the field-only import before moving the full post set.

Keep a source export, import log and rollback file. Store each with the date and database version. That record makes a second repair safer.

Automate count and type checks on a large site. A small site may be faster to inspect manually. Choose based on post count, field complexity and review time.

The verdict

Four checks and a field-only repair handle many WordPress import failures. Keep a recovery copy and an ID map before changing production data.

Questions people still ask

Can I fix custom fields without touching the database?

Sometimes. An importer can handle key mapping and field-only re-imports. Serialized values and relational IDs need serializer-aware tooling or controlled database work.

Why do custom fields show in the admin but not on the page?

The template may read another key, expect an array instead of text or serve cached output. Compare the exact key and type, clear the relevant cache and test the rendered page.

How do I tell if a serialized value is broken?

Serialized values often start with a:, s: or O: and contain byte counts. A value ending mid-string or failing a PHP decode test should be re-imported from the source.

How long does a field-only repair take on a large site?

Measure it with a test batch. Time depends on post count, field count, database speed and importer settings. Schedule production work only after that test passes.