Skip to content

ACF Support

If Advanced Custom Fields (ACF) is active on your WordPress site, the OC Magento Bridge plugin automatically detects it and injects ACF field data into the WordPress REST API responses for posts and pages.

When ACF is active, the OC_Bridge_ACF_Support class hooks into the WordPress REST API response filter. For every post or page included in a REST response, it:

  1. Calls get_fields($post_id) to retrieve all ACF fields for that post
  2. Sanitizes the field values (strips script tags, removes event handlers)
  3. Injects the sanitized fields into the REST response under the acf key

With ACF support active, post objects in REST responses include an acf property:

{
"id": 42,
"title": { "rendered": "My Post Title" },
"content": { "rendered": "<p>Post content...</p>" },
"acf": {
"hero_image_url": "https://blog.example.com/wp-content/uploads/hero.jpg",
"promo_text": "Special offer this week",
"show_banner": true,
"related_product_sku": "WH01-XS-Gray"
}
}

ACF field data is available via the Post data model’s getAcfFields() method (or through the raw API response array). In templates:

$acfFields = $post->getAcfFields();
$promoText = $acfFields['promo_text'] ?? '';

All standard ACF field types that return serializable values are supported, including text, textarea, number, email, URL, image (returns URL), select, checkbox, true/false, and relationship fields.

Complex nested fields (flexible content, repeater) are included as nested arrays.

ACF field values pass through basic sanitization before being injected into the response:

  • <script> and <style> tags are removed
  • on* event attributes are removed
  • javascript: protocol in URL fields is replaced with #