Home › Forums › General Issues › Pre-populate radio button with CPTs? › Reply To: Pre-populate radio button with CPTs?
Yes, I am actually doing this with a dropdown, but it is the same concept. The Documentation can be found here: https://www.advancedcustomfields.com/resources/acf-load_field/.
You can use something like add_filter('acf/load_field/name=cpt_all', 'acf_load_post_types');
to limit the use to any custom fields named cpt_all. Here is the code that I am using:
function acf_load_post_types( $field ) {
// reset choices
$field['choices'] = array();
$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);
}
// return the field
return $field;
}
add_filter('acf/load_field/name=cpt_all', 'acf_load_post_types');
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.