Hi,
Is it possible to retrieve a value from one specific options page. For example, having a repeater field “images” on multiple options pages (Page A, Page B, Page C, etc.), how can I get the one on “Page A”.
Currently, this works, but I feel (I have not tested it, though) it will get all values on all options pages:
get_field("images", "option");
What I would like is this:
get_field("images", "page-a");
Tried this as well, as it is stated in the manual the string has to contain “option” or “options”.
get_field("images", "page-a-option");
Is it possible?
Thanks!
Hi @matekk,
Thanks for the post.
I am afraid this is a current limitation in ACF.
To get this functionality, you will need to ensure that all options field names are unique and thus the field name will become the “option_name” value.
All the fields in the different options page will thus have unique identifiers. This will safeguard against the the wp_options table entry becoming too long. It has a limit of 64 chars.
Hi @matekk , contrary to what is said in https://www.advancedcustomfields.com/resources/get-values-from-an-options-page/, is it possibile with the ACF Api.
We create for example a “Page A” in this way:
$page_a = array(
'page_title' => 'Page A',
'menu_title' => 'Page A',
'post_id' => 'page_a'
);
acf_add_options_page($page_a);
And a “Option” page in this similar way:
$option = array(
'page_title' => 'Option',
'menu_title' => 'Option',
'post_id' => 'option'
);
acf_add_options_page($option);
Now you create a new Field Group with an “images” field and make this field visible when “Page Options” = “Page A” and similarly you create a new Field Group with an “images” field (it can also be a clone of the previous “images” field but watch out that the clone field name is something like “clone-images”) and make this field visible when “Page Options” = “Option”.
Now you can get the “images” field from “Page A” page with:
the field("images", "page_a")
and the “images” field from “Option” page with:
the field("images", "option")
because in Wp DB (‘wp_options’ page) the “images” field from “Page A” is saved as option_name ‘page_a_images” and the “images” field from “Option” page is saved as “option_images”.
Wish this would work for Options sub pages (acf_add_options_sub_page).. but, currently, the post_id param is only available to the acf_add_options_page function.
This would make for a clean admin menu and an easy way to target specific option page fields within specific template files (especially when dealing with archive pages or plugin template pages -eg event calendars etc.)
The topic ‘Retrieve value from a specific options page’ is closed to new replies.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.