Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'gform_pre_render_4', 'populate_radio' );
- add_filter( 'gform_pre_validation_4', 'populate_radio' );
- add_filter( 'gform_pre_submission_filter_4', 'populate_radio' );
- add_filter( 'gform_admin_pre_render_4', 'populate_radio' );
- function populate_radio( $form ) {
- foreach( $form['fields'] as &$field ) {
- if ( $field->type != 'radio' || strpos( $field->cssClass, 'primarycolor' ) === false ) {
- continue;
- }
- $args1 = array(
- 'showposts' => -1,
- 'post_type' => 'color',
- 'orderby' => 'title',
- 'order' => 'ASC'
- );
- $postslist = get_posts( $args1 );
- $choices = array();
- $input_id = 1;
- foreach ( $postslist as $post ) {
- if ( $input_id % 10 == 0 ) {
- $input_id++;
- }
- $colorname = get_post_meta($post->ID, '_pc_color_color_name', true);
- $colorcode = get_post_meta($post->ID, '_pc_color_color_code', true);
- $choices[] = array( 'text' => $colorname, 'value' => $colorname );
- $inputs[] = array( 'label' => $colorname, 'id' => "{$field_id}.{$input_id}");
- $input_id++;
- }
- $field->choices = $choices;
- $field->inputs = $inputs;
- }
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement