My homepage has embedded an ACF option page, which included two feature banners.
From dump() of the large feature banner, I got this array (showing parts that are relevant to this q):
array:24 [
......
"featureBanners" => array:2 [▼
0 => {#3489 ▼
+"url": "https://wordpress.test/2024/3/latest-drops"
+"shop_url": "https://wordpress.test/shop/latest-drops"
}
1 => {#3488 ▼
+"url": "https://wordpress.test/2024/3/sale"
+"shop_url": "https://wordpress.test/shop/sale"
}
]
"bannerSetting" => {#3489 ▼
+"url": "https://wordpress.test/2024/3/sale"
+"shop_url": "https://wordpress.test/shop/latest-drops"
......
]
I have added a “Shop Now” button on the url page.
When I’m on the url page and use dump(), there’s no “featureBanners” and “bannerSetting” displayed on the array. I need to access the “shop_url” sub-field in order to link the button to the url.
On homepage, I’ve used get_feature_post_url function to get the shop_url sub-field
{% if bannerPost.id is defined %}
......
{% set shopUrl = get_feature_post_url(bannerSetting.shop_url) %}
......
{% endif %}
Related twig functions in ArchiveHelperExtension.php:
public function getFunctions(): array
{
return [
......
new TwigFunction('editorial_feature_posts', [$this, 'getFeaturePosts']),
new TwigFunction('get_feature_post_url', [$this, 'getFeaturePostUrl']),
......
]
}
I was trying to access an ACF option’s sub-field shop_url outside of the option page. Expected to see bannerSetting on the actual url page as well but could not see it and so unable to access the shop_url as well.
Sorry really spent hours thinking on this.
Please let me know what can I do to fix this?
Much appreciated!