Advertisement
Guest User

Untitled

a guest
May 28th, 2013
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. add_filter("gform_pre_render_".FORM_EDIT_POST, "populate_category_checkbox");
  3. /**
  4. * Pre populate category chackbox fields frontend.
  5. */
  6. function populate_category_checkbox($form){
  7.  
  8.     if( $field["type"] == 'post_category' ){
  9.        
  10.         $categories = get_the_category( $postid );
  11.         if( $categories ){
  12.             foreach( $categories as $category ) {
  13.                 $selected_cats[] = $category->name;
  14.             }
  15.         }
  16.         ?>
  17.         <script type="text/javascript">
  18.             jQuery(document).ready(function($) {
  19.                 jQuery(document).bind('gform_post_render', function(){
  20.                     var selected_cats = <?php echo json_encode($selected_cats); ?>;
  21.                     var cat_container = $('.select-category');
  22.                     $('.select-category ul label').each(function(index, value) {
  23.                         if($.inArray($(this).text(), selected_cats) > -1) {
  24.                             $(this).prev().attr('checked', 'checked');
  25.                         }
  26.                     });
  27.                 });
  28.             });
  29.         </script>
  30.         <?php
  31.     }
  32.    
  33.     return $form;
  34. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement