I have a custom post type and I need one of its custom fields to automatically have the post id of that post. How can I do this?
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');
The type I’m using is a simple text field. This snippet helped me. Thank you!