0

add_filter( 'gform_pre_render_1', 'populate_checkbox' );
add_filter( 'gform_pre_validation_1', 'populate_checkbox' );
add_filter( 'gform_pre_submission_filter_1', 'populate_checkbox' );
add_filter( 'gform_admin_pre_render_1', 'populate_checkbox' );
function populate_checkbox( $form ) {
 foreach( $form['fields'] as &$field )  {
     //NOTE: replace 3 with your checkbox field id
    $field_id = 4;
    if ( $field->id != $field_id ) {
        continue;
    }
     $posts = get_posts( 'numberposts=-1&post_status=publish&post_type=home-builder' );
     $input_id = 1;
    foreach( $posts as $post ) {
       if ( $input_id % 10 == 0 ) {
            $input_id++;
        }
         $choices[] = array( 'text' => $post->post_title, 'value' => $post->ID );
        $inputs[] = array( 'label' => $post->post_title, 'id' => "{$field_id}.{$input_id}" );
         $input_id++;
    }
     $field->choices = $choices;
    $field->inputs = $inputs;
 }
 return $form;
}

Jagdish Sarma Asked question January 8, 2024
Add a Comment