I am trying to: Populate custom fields with rest api.
Link to a page where the issue can be seen: hidden link
I expected to see: Many more populated fields such as wpcf-affect-on-mythos
Instead, I got: Some populated fields and many blank custom fields
I've included an image of one of the post's meta. You can see a few of the fields there and they have been populated correctly. However many other fields exist on the Toolset backend, yet are not present in the database. I've provided an image of one of them as well.
My script uses the following mapping which works for some fields but not many others:
JSON_TO_WPCF_MAPPING = {
# "archetype_name" is handled separately using sheet value
"archetype_quote": "wpcf-archetype-quote",
"archetype_traits": "wpcf-archetype-traits",
"archetype_examples": "wpcf-archetype-examples",
"archetype_known_for": "wpcf-archetype-known-for",
"symbolism_meaning_content": "wpcf-symbolism-meaning-content",
I've Tried:
- Flushing cache
- Resaving custom fields and custom post type
- Disabling all plugins
- Many other things I've forgot 😛
Very interesting update: I went into an individual post and just manually put "asdf" in every custom field. After saving, and then checking the database, *all the fields were present!*. I went back and deleted all the "asdf"s and saved again...the fields still existed in the database.
One major problem left - no other posts benefited from this. They are all still missing a dozen custom fields from their post meta database tables.
Ok I was able to figure it out. I had to put something like the following in the functions.php
add_action('init', 'expose_toolset_fields_to_rest');
function expose_toolset_fields_to_rest() {
// Define the list of Toolset meta keys you want to expose
$fields = [
'wpcf-archetype-name', // From sheet name
'wpcf-archetype-quote',
'wpcf-archetype-traits',
'wpcf-archetype-examples',
But why do I have to do this manually? Shouldn't Toolset do this? I don't like the idea that all my future custom fields must be input this way and also that a theme update could wipe them out.