Home › Forums › General Issues › Automatically populate custom field with post ID › Reply To: Automatically populate custom field with post ID
I’m not sure the field type, but you can populate a select field like this. Place the following in your functions.php
file.
function acf_load_field_choices( $field ) {
// Create an empty array
$field['choices'] = array();
// Populate field with the current post id
$field['choices'][0] = get_the_ID();
// Return the result
return $field;
}
add_filter('acf/load_field/name=test', 'acf_load_field_choices');
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.