Support

Account

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');