By this setup this particular page (“Banner 1”) and all products each are given two fields: A link and a banner. Now you can assign them a link and a banner each. So, if you call
get_field( 'my_custom_link_in_pages' ) on a product page, you are grabbing the link that you have assigned to this product. If you have not assigned this product a link, the function will return an empty value.
Depending on what exactly your are trying to accomplish, there are three ways to solve this:
1. You can assign your product the same link and banner that you have assigned “Banner 1”, so they now belong to the product as well.
2. You can fetch the fields of “Banner 1” directly on every product page like this:
get_field( 'my_custom_link_in_pages' , $the_id_of_the_banner1_page )
3. You can remove the second field group condition, so the fields no longer apply to product pages, then create a second field group, which contains a
Post Object field. Then you can assign each product a page the link and banner of which to use, like this:
<?php $the_page_id = get_field( 'the_assigned_page' ); ( is_object( $the_page_id ) ) ? $the_page_id = $the_page_id->ID : null ; $the_link = get_field( 'my_custom_link_in_pages' , $the_page_id );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!