Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // update the '51' to the ID of your form.
- add_filter('gform_pre_render_6', 'populate_posts');
- function populate_posts($form){
- foreach($form['fields'] as &$field){
- if($field['type'] != 'select' || strpos($field['cssClass'], 'populate-posts') === false)
- continue;
- // you can add additional parameters here to alter the posts that are retreieved
- // more info: http://codex.wordpress.org/Template_Tags/get_posts
- $posts = get_posts('numberposts=-1&category=1&orderby=title&order=ASC&post_status=publish');
- // update 'Select a Post' to whatever you'd like the instructive option to be
- $choices = array(array('text' => 'Select a Post', 'value' => ' '));
- foreach($posts as $post){
- $choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
- }
- $field['choices'] = $choices;
- }
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement