Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Original http://pastie.org/1617402
- // Original by David Smith, Ounce of Talent http://ounceoftalent.com/about/
- // Modified by Chris Hajer October 7, 2012 for
- // http://www.gravityhelp.com/forums/topic/drop-down-with-posts-from-certain-author#post-79310
- /* Display Posts as Choices */
- add_action('gform_pre_render', 'populate_post_type');
- function populate_post_type($form){
- $dropdown_field = 2; // update to the ID of your drop down field
- $post_type = 'review'; // update
- $choices = ounce_posts_as_choices($post_type);
- foreach($form['fields'] as &$field){
- if($field['id'] == $dropdown_field)
- $field['choices'] = $choices;
- }
- return $form;
- }
- function ounce_posts_as_choices($post_type = 'post', $first_choice = '') {
- $posts = get_posts("post_type=$post_type");
- // determine the logged in user
- global $current_user;
- get_currentuserinfo();
- $userid = $current_user->ID;
- $choices = array();
- $i = 0;
- if($first_choice){
- $choices[$i]['text'] = $first_choice;
- $choices[$i]['value'] = '';
- $i++;
- }
- foreach($posts as $post) {
- // only return posts for the logged in user
- if ($userid == $post->post_author) {
- $choices[$i]['text'] = $post->post_title;
- $choices[$i]['value'] = $post->ID;
- $i++;
- }
- }
- return $choices;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement