Advertisement
Guest User

Untitled

a guest
Jul 19th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. add_filter("gform_pre_render", "ictr_populate_boeken");
  3. add_filter("gform_admin_pre_render", "ictr_populate_boeken");
  4. function ictr_populate_boeken($form, $form_id = 14, $field_id = 16, $field_type = 'checkbox') {
  5.     global $post;
  6.    
  7.     if(!in_array($form['id'], array(14, 15))) {
  8.         return $form;
  9.     }
  10.  
  11.     $args_posts = array(
  12.         'post_type' => 'boek',
  13.         'orderby' =>'titel',
  14.         'order' => 'ASC',
  15.         'numberposts' => -1
  16.     );
  17.     $posts = get_posts($args_posts);
  18.  
  19.     // Creating drop down item array.
  20.     $items = array();
  21.  
  22.     //Adding post titles to the items array
  23.     foreach($posts as $i => $item) {
  24.         $tmp = array(
  25.             'value' => $item->post_title,
  26.             'text' => $item->post_title
  27.         );
  28.         if($item->ID == $post->ID)
  29.             $tmp['isSelected'] = true;
  30.  
  31.         $items[] = $tmp;
  32.     }
  33.  
  34.     foreach($form['fields'] as &$field) {
  35.         if($field['id'] == $field_id) {
  36.             $field['choices'] = $items;
  37.             $field['type'] = $field_type;
  38.         }
  39.     }
  40.  
  41.     return $form;
  42. }
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement