Home › Forums › Backend Issues (wp-admin) › Options select in Edit Posts
I have a repeater in an Options page that I want to display in the Edit Post page as a select menu. More specifically, I have a manageable list of disclosures in the Options page, I want the author to have the ability to select from the list when creating a post. It seems that acf_add_options_sub_page() would be how to do it but I can’t get anything to show up on the Edit post page. Is this even possible?
You would need to create a select field in a group and set the location for the post. Then you would need to dynamically generate the choice values for this field from the values saved for the options page. https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/
Thanks for your reply but I’m not understanding all the variable connections. I’ve created a new field group called “Post Fields” with a select field called “disclosure_select” that’s assigned to show on post type “post”. It does, it’s empty. I have my options group called “Post Disclosures” with a repeater field called disclosure_picker. And in my functions.php I have”
// ACF load disclosure fields
function acf_load_disclosures( $field ) {
// reset choices
$field[‘choices’] = array();
// if has rows
if( have_rows(‘disclosure_picker’, ‘option’) ) {
// while has rows
while( have_rows(‘disclosure_picker’, ‘option’) ) {
// instantiate row
the_row();
// vars
$value = get_sub_field(‘value’);
$label = get_sub_field(‘label’);
// append to choices
$field[‘choices’][ $value ] = $label;
}
}
// return the field
return $field;
}
add_filter(‘acf/load_field/name=disclosure_select’, ‘acf_load_disclosures’);
I’m sorry if it seems I’m doing something obviously stupid here.
I don’t see anything obviously wrong with your code.
You can try
1) use the field key variant of the load field hook
2) set the priority of your filter to > 10 to ensure it runs after ACF
add_filter('acf/load_field/key=field_1234yourfieldkey', 'acf_load_disclosures', 20);
I’m not familiar with field keys or where to find them. Should the key be for disclosure_select (select field on the post) or disclosure_picker (options repeater)?
When editing a field group click on screen options and check the box to show the field keys. You would use the field key of the field you are populating, the select field on the post. Because it is a repeater sub field you must use the field key, not the field name.
The topic ‘Options select in Edit Posts’ 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.