How can I dynamically select the default post object select choice or value?
For example, when creating a New book (post type) an acf post_object select presents a list of book authors, read from a book_author post type.
I want a to dynamically specify one (or more on multiselect) book_authors that will be selected by default from the book_author post type.
Ah, the late timing of the prepare_field filter seems to make this possible via the $field[‘value’] key
function preselect_an_option( $field ) {
if (isset($_GET['book_author'])){ // or however you get the value dynamically
$field['value'] = $_GET['book_author']; // this is where it gets selected!
}
return $field;
}
add_filter('acf/prepare_field/name=book_author', 'preselect_an_option');