Skip to content

[00] Subset Clone, Guide

Duplicated post missing its ACF fields? Why it happens

Why a duplicated post can lose its ACF fields, repeater rows or flexible content, how to find the rows that didn't come across, and how to copy them intact.

Published
Fix uses
Subset Clone (free)
Reading time
4 min

Where the fields live

Advanced Custom Fields (ACF) saves a post’s field values as custom fields, which WordPress keeps in the wp_postmeta table. ACF’s update_field reference (opens in a new tab) explains that each saved value also gets a reference to the field’s key, which is how ACF connects a value with its field settings.

On a post edited in ACF, that reference is a second row named after the field with a leading underscore. A field called hero_title has a hero_title row with the text and a _hero_title row holding a key such as field_64a1b2c3. Repeater rows and flexible content layouts are stored the same way, as more rows of post meta.

So a duplicate only has its ACF fields if every one of those rows reaches the copy unchanged.

The duplicator is set to skip those keys

Yoast Duplicate Post has a Do not copy these fields setting, described in its source (opens in a new tab) as a comma-separated list of meta fields that must not be copied. It accepts * to match any run of letters, numbers or underscores, such as field*.

A pattern added for another plugin can match your ACF field names too. A pattern that starts with an underscore can match ACF’s reference rows. Open the setting and check each entry against the names of the fields that went missing.

The values came across but the references didn’t

A copy made by your own code, or by an import, sometimes writes only the field names you know about. The values land on the copy, but the underscore rows that point to the field keys don’t.

ACF’s update_field reference says the field key should be used when saving a new value to a post, so that ACF can create the reference. A script that calls update_field() with the field name on a freshly created post can leave the value without one. Without the reference, ACF can’t connect the value to its settings, so a formatted value, such as an image field’s array of image data, may not come back the way the original’s does.

Backslashes and serialized values changed on the way

A duplicator that copies meta with core’s add_post_meta() has to prepare each value first. The add_post_meta reference (opens in a new tab) says the value is expected to be slashed on input and is passed through stripslashes(). Arrays and objects are stored as serialized data.

If the copying code reads a value with get_post_meta() and writes it back without adding slashes, any backslash in it is removed. Text containing a backslash changes, and JSON that escapes characters can stop being valid. Arrays, such as a flexible content field’s list of layouts, are unserialized and serialized again on the way through.

Check what the copy has

WP-CLI’s wp post meta list (opens in a new tab) prints every custom field on a post. Export the original’s and the copy’s, then compare them. Replace 12 and 15 with the original’s and the copy’s IDs:

wp post meta list 12 --fields=meta_key,meta_value --format=csv > original.csv
wp post meta list 15 --fields=meta_key,meta_value --format=csv > copy.csv
diff original.csv copy.csv

Read the differences like this:

  • A field name and its underscore row both missing: the duplicator skipped the key. Check its exclusion settings.
  • The field name present but its underscore row missing: the reference wasn’t copied.
  • Both rows present but the value different: the value was changed in transit. Look for missing backslashes or a different serialized length.

Some differences are expected, such as edit locks or a duplicator’s own marker linking the copy to its original. To look at one field and its reference, add --keys=hero_title,_hero_title.

How Subset Clone copies custom fields

Subset Clone copies the meta rows as they’re stored, byte for byte and in the order they were saved. We read the original’s rows straight from wp_postmeta and insert the same stored strings on the copy, without going through add_post_meta(). Nothing is unslashed or serialized again, so slashed JSON and serialized arrays come across as they were.

The reference rows are ordinary meta rows, so ACF’s field values, repeater rows and flexible content layouts arrive with the field key references that tie them to their field groups. Core’s add_post_meta and added_post_meta actions still fire for each row, so plugins that watch for new meta still hear about it.

We leave out a short list of keys by default:

  • WordPress’s bookkeeping, such as edit locks, old slugs and dates, and trash and ping markers.
  • The copy’s link back to its original, which is set afresh for the copy.
  • Caches that belong to the original’s ID, such as Elementor’s CSS status, and markers from Rank Math, Yoast Duplicate Post and WPML.

None of those are ACF fields. A developer can add or remove keys with the subset_dup_excluded_meta_keys filter, described in the developer reference. Data a plugin keeps in its own database tables isn’t post meta, so it isn’t copied.

To try it on the post that lost its fields, click Duplicate under the post in its list, or run the WP-CLI command, then compare the two posts with the commands above:

wp subset duplicator duplicate 12 --user=admin --porcelain

The copy is always a draft. Getting started with Subset Clone lists what else the copy includes and who can make one.