Retrieving ACF fields from specific options pages

Hello, I use multiple ACF options pages on most of my sites. I usually create a unique options page for each custom post type that the site uses. ACF provides a great way to do this by specifying a post id value for each unique options page like so (look at the post_id option):

<?php
$cpts = array(
    'work'          => 'Work',
	'people'        => 'People',
	'location'      => 'Location',
	'brandblocks'   => 'Brand Block',
	'video'         => 'Video',
	'open-position' => 'Open Position',
);

foreach ( $cpts as $cpt_slug => $label )
{
	$acf_retrieval_id = 'cpt_' . $cpt_slug;

	// post type settings/options page
	$cpt_acf_page = array(
		'page_title'  => $label . ' Settings',
		'menu_title'  => $label . ' Settings',
		'parent_slug' => 'edit.php?post_type=' . $cpt_slug,
		'menu_slug'   => $cpt_slug . '-archive',
		'capability'  => 'edit_posts',
		'post_id'     => $acf_retrieval_id,
		'position'    => false,
		'icon_url'    => false,
		'redirect'    => false
	);

	// Now add the cpt option page
	acf_add_options_page( $cpt_acf_page );
}

This is a great way to provide configuration options and store values for custom post type archive pages, without cluttering a global ACF options page. It provides a much nicer user experience for the site owner, where they can manage post type specific settings and values on a post type specific options page, and they can manage global site options on the main options page.

When I need to retrieve a value from a certain CPT options page, I just use the unique id. Something like: get_field('cpt_location', 'locations_intro_text'). Unfortunately this does not work in Cornerstone which is a huge bummer. I’m hoping you can add this functionality. Currently you can retrieve fields from the main options page (i.e. {{dc:acf:option_field field="locations_intro_text"}}), and you can retrieve values from a specific post ID, but I guess the post ID field only accepts integers, is that correct? When I try the following, I get nothing: {{dc:acf:post_field post="cpt_location" field="locations_intro_text"}}

This seems like it could be a very simple fix by simply allowing a string to be entered as the post ID.

Please let me know if this can be added soon. Thanks!

1 Like

Hey @adaptifyDesigns,

Thanks for writing in!

Regretfully custom coding is beyond the scope of our support. It is best that you consult a 3rd party developers who are more well-versed with the ACF Pro plugin. If you are editing the page and using the ACF Pro fields with the Builder, it is best that you use the ACF Pro dynamic contents instead. If you are not familiar with the Dynamic Content yet, kindly check this out:

Note: We are unable to provide support for customizations under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Best Regards.

Hmmm… I don’t think you have understood my post. I will try to explain it again, but can you please also have someone else review this? I think this is a very important missing component of Cornerstone’s ACF Pro integration.

I have a good understanding of how the Dynamic Content works in Cornerstone. I’ve read all of the documentation about it, including the article that specifically covers ACF Pro and Loopers. But the ACF Pro dynamic content is missing a crucial feature. This is not a “custom code” support request. This is a notification that Cornerstone’s current implementation of ACF dynamic content is incomplete and does not allow for multiple ACF options pages.

The current Cornerstone ACF dynamic content feature allows for retrieving values from only one ACF options page. If you consider my above code to be “custom code” then that would mean that the ACF Options page is also “custom code,” because it requires the theme developer to use the acf_add_options_page function in order to create and configure the ACF Options page. What I am doing is the same thing, but I am using the post_id option which ACF Pro provides for that function. It is not custom code. It is an option that is provided by the ACF Pro plugin that enables the user to create more than one Options page and then retrieve values from those unique options pages. It’s part of the plugin.

So, if Cornerstone is hoping to provide a coherent and complete integration with ACF Pro, then it should also have the capability to retrieve values from multiple options pages, using their unique post_id.

Does that make sense? I would appreciate it if you could reflect back to me what you think I’ve said, so that I know whether or not I’ve been understood. Your initial response to my post made me think that you might not have understand what I was trying to communicate.

Thank you in advance for taking this seriously.

1 Like

Hi @adaptifyDesigns,

Thank you for the clarification, but in addition on explaining what you did, please also explain what you’re trying to do. Does using dynamic content {{dc:acf:post_field field="test_field" post="161"}} does not work? Please clarify.

Cheers,

The above works fine, but it is not what I’m trying to do.

This also works fine: {{dc:acf:option_field field="test_field"}} but it is also not what I’m trying to do.

What I’m trying to do is retrieve an ACF field value from a specific ACF options page, using the post_id that I have assigned to that specific options page.

Take a look at the ACF Pro documentation on creating multiple options pages. Scroll down to the post_id parameter. This parameter makes it possible to assign a unique id to a specific options page. But when I create an options page this way, and then try to use the unique id to retrieve values from it in Cornerstone, it does not work. The ACF Pro docs say that the options page post_id parameter can be set to either a numeric id or a string. I have tried both, but neither have worked when trying to retrieve the field values in Cornerstone.

I have tried: {{dc:acf:post_field field="test_field" post="unique_string_id"}}
And I have tried: {{dc:acf:post_field field="test_field" post="161"}}
…where unique_string_id and 161 are the unique ids that I assigned to the specific options pages, but neither of the above has successfully retrieved the field values from those options pages. I know that the ids are correct, because when I use php to retrieve the values, the normal ACF functions work just fine.

The reason it is useful to assign unique ids to multiple ACF options pages is because sometimes it can be very efficient and clean to assign the same ACF field group to multiple post types (for example). Rather than having to create “portfolio featured posts”, “people featured posts”, “testimonial featured posts”, etc., you could instead create a single “featured posts” field group and assign it to the Portfolio Options Page, the People Options Page, the Testimonial Options Page, etc., and then you could retrieve the values for those fields by using the unique options page ids (i.e. 'acf_portfolio_settings', 'acf_people_settings', 'acf_testimonial_settings', etc.).

Hopefully that clears up what I’m trying to accomplish, and the above linked ACF Pro documentation shows that it is a feature that is included in the ACF Pro plugin.

Please let me know if that makes sense. Thanks.

Hi @adaptifyDesigns,

Unfortunately, the option for this is not available currently in the Dynamic Content. I will check and add this to feature request so it might be taken into account in the future.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.