Home › Forums › General Issues › Pre-populate radio button with CPTs? › Reply To: Pre-populate radio button with CPTs?
Jez,
If I am understanding you correctly, you have a Custom Field in CPT b and you want CPT a to have access to the options that are selected?
To target a specific field in a CPT you would change this block
$args = array(
'public' => true
);
$post_types = get_post_types($args);
foreach ($post_types as $post_type) {
if ($post_type !== 'attachment' && $post_type !== 'page')
$field['choices'][$post_type] = ucfirst($post_type);
}
to something like
$cpt_custom_field = get_field($cpt_id, 'the_name_of_the_specific_field');
foreach ($cpt_custom_field['choices'] as $value=>$label) {
$field['choices'][ $value ] = [ $label ];
}
Or whatever you want to replace the information with. Nested repeater fields are slightly more complicated, but code examples for that are in the docs. You could create a colors array and assign the select to those, you can grab all post names from a CPT and assign those, etc. You just need to change the above code to match what you are loading into the choices field.
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.