Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://www.gravityhelp.com/forums/topic/populate-a-drop-with-categories-from-current-post
- // update the '33' to the ID of your form
- add_filter('gform_pre_render_33', 'populate_cats');
- function populate_cats($form){
- // loop through each of the form fields...
- foreach($form['fields'] as &$field){
- // ... and skip this function if this is not a Select box or a cssClass of populate-categories is not present
- // be sure to add the CSS Class to your select box Advanced tab
- if($field['type'] != 'select' || strpos($field['cssClass'], 'populate-categories') === false)
- continue;
- // here's where we populate the drop down
- // update 'Rim Size' to whatever you'd like the instructive option to be
- $choices = array(array('text' => 'Rim Size', 'value' => ' '));
- // the WordPress function get_the_category will return all categories for the current post
- // http://codex.wordpress.org/Function_Reference/get_the_category
- foreach((get_the_category()) as $category) {
- $choices[] = array('text' => $category->cat_name, 'value' => $category->cat_name);
- }
- // populate $field['choices'] with our array of choices
- $field['choices'] = $choices;
- }
- // always return the $form
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement