<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Specific author dropdown guest blog submission form</title>
		<link>https://legacy.forums.gravityhelp.com/topic/specific-author-dropdown-guest-blog-submission-form</link>
		<description>Gravity Support Forums Topic: Specific author dropdown guest blog submission form</description>
		<language>en-US</language>
		<pubDate>Sun, 19 Apr 2026 23:48:36 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/specific-author-dropdown-guest-blog-submission-form" rel="self" type="application/rss+xml" />

		<item>
			<title>David Smith on "Specific author dropdown guest blog submission form"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/specific-author-dropdown-guest-blog-submission-form#post-69745</link>
			<pubDate>Mon, 06 Aug 2012 18:19:45 +0000</pubDate>
			<dc:creator>David Smith</dc:creator>
			<guid isPermaLink="false">69745@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi tfmwa,&#60;/p&#62;
&#60;p&#62;Try using this code to only retrieve an array of users of a specific role:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://www.wprecipes.com/how-to-get-all-users-having-a-specific-role&#34; rel=&#34;nofollow&#34;&#62;http://www.wprecipes.com/how-to-get-all-users-having-a-specific-role&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;If you include that function, you could then replace this in your code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;[php]
$wp_user_search = $wpdb-&#38;gt;get_results(&#38;quot;SELECT ID, display_name FROM $wpdb-&#38;gt;users ORDER BY ID&#38;quot;);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;...with this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;[php]
$authors = getUsersWithRole(&#38;#39;editor&#38;#39;);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;You will need to update the rest of the code accordingly to use this new variable.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>tfmwa on "Specific author dropdown guest blog submission form"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/specific-author-dropdown-guest-blog-submission-form#post-68518</link>
			<pubDate>Mon, 30 Jul 2012 08:34:02 +0000</pubDate>
			<dc:creator>tfmwa</dc:creator>
			<guid isPermaLink="false">68518@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;First I'd like to thank Shelly, other forum users and administrators for the thread that can be found here: &#60;a href=&#34;http://www.gravityhelp.com/forums/topic/post-authors&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/forums/topic/post-authors&#60;/a&#62; and threads linked to from that thread. &#60;/p&#62;
&#60;p&#62;It has allowed me to piece together a dropdown in a form. It contains all users, which allows people to create their blog post without logging in and without having to create 1 form for every guest blogger. &#60;/p&#62;
&#60;p&#62;We'd like to build on this and have the user dropdown list only users that have a specific Wordpress user role. So the list won't be as long and filled with names that don't need to be in there. &#60;/p&#62;
&#60;p&#62;My knowledge of PHP is passive, so I'm limited to breaking it (often) and otherwise interpreting and modifying existing code when I look at it and/or break it repeatedly until I get it right. &#60;/p&#62;
&#60;p&#62;Would anyone be willing to build on the code provided in the other threads and help us out by providing the code that needs to be added or modified, so the dropdown only lists users with a specific user role?&#60;/p&#62;
&#60;p&#62;[edit]&#60;br /&#62;
Just discovered that the author field is blank in the WP dashboard if submitting the form when NOT logged in. I'm investigating this at the moment, but if anyone wants to chime in on that before I remove this message, please do so. :D&#60;br /&#62;
[/edit]&#60;/p&#62;
&#60;p&#62;The owner and myself (and future users) would be very grateful. Thanks in advance. :)&#60;/p&#62;
&#60;p&#62;The role we want to populate the dropdown with is the Wordpress 'Author' role (Auteur in nl_NL).&#60;br /&#62;
The code I'm currently using at &#60;a href=&#34;http://goo.gl/xO7GA&#34; rel=&#34;nofollow&#34;&#62;http://goo.gl/xO7GA&#60;/a&#62; is:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;quot;gform_pre_render_8&#38;quot;, populate_dropdown);

function populate_dropdown($form){

global $wpdb;
$wp_user_search = $wpdb-&#38;gt;get_results(&#38;quot;SELECT ID, display_name FROM $wpdb-&#38;gt;users ORDER BY ID&#38;quot;);

//Creating drop down item array.
$items = array();

//Adding initial blank value.
$items[] = array(&#38;quot;text&#38;quot; =&#38;gt; &#38;quot;&#38;quot;, &#38;quot;value&#38;quot; =&#38;gt; &#38;quot;&#38;quot;);

 //Adding post titles to the items array
foreach ( $wp_user_search as $userid )
	$items[] = array(&#38;quot;value&#38;quot; =&#38;gt; $userid-&#38;gt;display_name, &#38;quot;text&#38;quot; =&#38;gt; $userid-&#38;gt;display_name);

 //Adding items to field id 8. field_1_2
    foreach($form[&#38;quot;fields&#38;quot;] as &#38;amp;$field)

        if($field[&#38;quot;id&#38;quot;] == 21){
            $field[&#38;quot;type&#38;quot;] = &#38;quot;select&#38;quot;;
            $field[&#38;quot;choices&#38;quot;] = $items;

        }

    return $form;
}
//Override default author with author selected from dropdown
add_filter(&#38;#39;gform_post_data_8&#38;#39;, &#38;#39;update_post_author&#38;#39;, 10, 2); // &#38;quot;2&#38;quot; in &#38;quot;gform_post_data_2&#38;quot; is the form ID.
function update_post_author($post_data, $form) {
    $author_id = rgpost(&#38;quot;input_21&#38;quot;); // grab the value from field 5
    $post_data[&#38;#39;post_author&#38;#39;] =  $author_id;
    return $post_data;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
