Support

Account

Home Forums ACF PRO attach comment to custom post type entry Reply To: attach comment to custom post type entry

  • nice one elliot! this leads me to the right direction. but i think i found a bug?! i am using ACF 5.0.3.
    this is my function:

    /* auto populate acf field with comment IDs */
    function my_acf_load_field( $field ){
    
    	$assignedpost = get_field('produktblog');
    	$comments = get_comments(array(
    		'status' => 'approve',
    		'post_id' => $assignedpost->ID
    	));
    	if( is_array($comments) )
    	{
    		foreach( $comments as $key=>$comment )
    		{
    			$field['choices'][ $key ] = $comment->comment_content;
    			$field['default_value'][ $key ] = $comment->comment_ID;
    		}
    	}
        return $field;
    }
     
    // v4.0.0 and above
    add_filter('acf/load_field/name=kommentare', 'my_acf_load_field');

    and this is the print_r from $field:

    Array
    (
        [ID] => 150
        [key] => field_53e327ee805e6
        [label] => Kommentare
        [name] => kommentare
        [prefix] => 
        [type] => select
        [value] => 
        [menu_order] => 0
        [instructions] => 
        [required] => 0
        [id] => 
        [class] => 
        [conditional_logic] => 0
        [parent] => 6
        [_name] => kommentare
        [_input] => 
        [_valid] => 1
        [choices] => Array
            (
                [0] => kommentar3
                [1] => kommentar2
                [2] => kommentar1
            )
    
        [default_value] => Array
            (
                [0] => 7
                [1] => 6
                [2] => 5
            )
    
        [allow_null] => 1
        [multiple] => 1
        [ui] => 0
        [ajax] => 0
        [placeholder] => 
        [disabled] => 0
        [readonly] => 0
    )

    the select field accepts the choices but not the values:
    https://www.dropbox.com/s/h4ek9agt4wk97vg/Screenshot%202014-08-07%2009.47.48.png
    so as you can see, the value is still 0,1,2. but it has to be 7,6,5