Created
April 15, 2015 21:30
-
-
Save szbl/6b5346a1842697ffa88e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'gform_pre_render_1', 'szbl_gform_render_test' ); | |
function szbl_gform_render_test( $form ) | |
{ | |
foreach ( $form['fields'] as $key => $field ) | |
{ | |
if ( 'select' == $field->type ) | |
{ | |
if ( 5 == $field->id ) | |
{ | |
$newfield = $field; | |
$posts = get_posts( 'post_per_page=999' ); | |
$newfield->choices = array(); | |
foreach ( $posts as $post ) | |
{ | |
$newfield->choices[] = array( | |
'text' => $post->post_title, | |
'value' => $post->ID, | |
'isSelected' => false, | |
'price' => 0 | |
); | |
} | |
$form['fields'][ $key ] = $newfield; | |
} | |
} | |
} | |
return $form; | |
} | |
// add_filter( 'gform_pre_render_1', 'szbl_gform_render_post_type' ); | |
function szbl_gform_render_post_type( $form ) | |
{ | |
foreach ( $form['fields'] as $key => $field ) | |
{ | |
if ( 'select' == $field->type ) | |
{ | |
if ( 5 == $field->id ) | |
{ | |
$newfield = $field; | |
$post_types = get_post_types(); | |
$newfield->choices = array(); | |
foreach ( $post_types as $post_type ) | |
{ | |
$data = get_post_type_object( $post_type ); | |
$newfield->choices[] = array( | |
'text' => $data->labels->name, | |
'value' => $post_type | |
); | |
} | |
$form['fields'][ $key ] = $newfield; | |
} | |
} | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment