Home Forums Backend Issues (wp-admin) Dynamic choice select on post object selects


Dynamic choice select on post object selects

  • 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');
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Dynamic choice select on post object selects’ is closed to new replies.