Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter("gform_pre_render_".FORM_EDIT_POST, "populate_category_checkbox");
- /**
- * Pre populate category chackbox fields frontend.
- */
- function populate_category_checkbox($form){
- if( $field["type"] == 'post_category' ){
- $categories = get_the_category( $postid );
- if( $categories ){
- foreach( $categories as $category ) {
- $selected_cats[] = $category->name;
- }
- }
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- jQuery(document).bind('gform_post_render', function(){
- var selected_cats = <?php echo json_encode($selected_cats); ?>;
- var cat_container = $('.select-category');
- $('.select-category ul label').each(function(index, value) {
- if($.inArray($(this).text(), selected_cats) > -1) {
- $(this).prev().attr('checked', 'checked');
- }
- });
- });
- });
- </script>
- <?php
- }
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement