Support

Account

Home Forums Front-end Issues Post Object Field – Set selected value programatically Reply To: Post Object Field – Set selected value programatically

  • Hi @bigdogdigital

    I believe you can do it by using the acf/prepare_field hook. Here’s an example to do it:

    function my_acf_prepare_field4( $field ) {
        
        if( isset($_GET['post']) ){
            $post_id = $_GET['post'];
            $field['value'] = $post_id;
        }
        
        return $field;
        
    }
    
    // name
    add_filter('acf/prepare_field/name=custom_field_name', 'my_acf_prepare_field4');

    @maxaud

    ACF uses select2 for the post object. To do it, please take a look at this thread: http://stackoverflow.com/questions/19639951/how-do-i-change-selected-value-of-select2-dropdown-with-jqgrid. Also, please take a look at this page to learn more how to use ACF with Javascript: https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/.

    I hope this helps 🙂