Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter("gform_pre_render", "ictr_populate_boeken");
- add_filter("gform_admin_pre_render", "ictr_populate_boeken");
- function ictr_populate_boeken($form, $form_id = 14, $field_id = 16, $field_type = 'checkbox') {
- global $post;
- if(!in_array($form['id'], array(14, 15))) {
- return $form;
- }
- $args_posts = array(
- 'post_type' => 'boek',
- 'orderby' =>'titel',
- 'order' => 'ASC',
- 'numberposts' => -1
- );
- $posts = get_posts($args_posts);
- // Creating drop down item array.
- $items = array();
- //Adding post titles to the items array
- foreach($posts as $i => $item) {
- $tmp = array(
- 'value' => $item->post_title,
- 'text' => $item->post_title
- );
- if($item->ID == $post->ID)
- $tmp['isSelected'] = true;
- $items[] = $tmp;
- }
- foreach($form['fields'] as &$field) {
- if($field['id'] == $field_id) {
- $field['choices'] = $items;
- $field['type'] = $field_type;
- }
- }
- return $form;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement