JSON-LD support - exclude fields
R
Rich Holman
This is an excellent addition to the plugin in 6.8 Beta 2, thankyou. We were actually in the process of creating our own JSON-LD embed for custom post types, so nice to know this is coming in a future release. I've been testing the feature locally and it's excellent.
However on some of our post types, some fields contain internal/administrative data that shouldn't appear in the public JSON-LD output (e.g., CRM IDs, internal notes, admin-only flags).
We found a workaround:
Using the acf/schema/data filter to manually remove fields from the final JSON-LD output:
add_filter('acf/schema/data', function($data) {
$exclude = ['internal_id', 'internal_notes'];
foreach ($data['additionalProperty'] as $key => $prop) {
if (isset($prop['value']) && is_array($prop['value'])) {
foreach ($exclude as $field_name) {
unset($data['additionalProperty'][$key]['value'][$field_name]);
}
}
}
return $data;
});
wondering if there is a plan to exclude fields from the UI?
Liam Gladdy
Hey Rich,
Thanks your feedback, we'll look into this with our product and design team.
I also wanted to make you aware of the filters:
acf/schema/post_field_objects
acf/schema/post_field_objects/post_type={type}
These are likely a better place to remove fields from the output, as this would be more performant.