
Any “new field type” devs out there have any success creating a select dropdown?
Trying to do this: Populate post titles in select dropdown. Store the selected post slug as the value.
Utilizing this template. https://github.com/AdvancedCustomFields/acf-field-type-template
Select dropdown working, and posts populating correctly. Getting stuck on the storing of the post slug as value. Any optimization or suggestions greatly appreciated!
function render_field( $field ) {
$field['type'] = 'select';
$field['choices'] = array();
$postTypes = $field['post_type'];
echo '<pre>';
print_r( $field );
echo '</pre>';
if ( $postTypes ) {
foreach ($postTypes as $index=>$post) {
$postChildren = get_posts([
'post_type' => $post,
'post_status' => 'publish',
'numberposts' => -1
]);
foreach ($postChildren as $childrenIndex=>$child) {
$field['choices'][$childrenIndex] = $child->post_title;
}
}
}
acf_render_field( $field );
}
//this runs after a user hits "Update"
function update_value( $value, $post_id, $field ) {
$value = "this overrides";
return $value;
}