PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Post Authors

  1. I'm trying to create a form where the end user can fill it in from the front-end of the site and create a post within the system. That in itself isn't an issue (I've got that covered). the issue is that the site I'm working on has multiple authors, and only one person is putting in the posts for these authors. Each author has it's own section (not exactly their own "site", otherwise I'd use multi-site - but this isn't THAT complicated.) - an author page where they have updates every now and then. The person who puts in the posts needs to be able to fill in the form (to create a post) and then be able to choose which author she's posting as.

    In the back-end of WordPress, you can do this by selecting a username from the dropdown. But I can't seem to sort out a method how to do this with Gravity Forms. It seems the only option I have is to either set a default user, or set the author as whoever is logged in.

    I've found a few tutorials on how to do this by email address, but that's not an option either - everyone's set to have the same email address (because there's only one contact dealing with inputting everything on the site - and yes, you can use one email address for multiple users, which is how it's currently set up). So really, what I need is to just have a dropdown with all the usernames for the lady putting in the posts to choose from.

    Yes, I realize she could do this by simply writing a post from the back end, and problem solved - but apparently she finds the back end of Wordpress "ugly and confusing", so she just wants a form on the front end of the site so she can put in the stuff, set the author and publish.

    So I have it all, but I just can't sort out how to get that dropdown list of authors so when she submits the form, the post is published under the proper username. I'm thinking I have to add a bit to the default "Post Title" field so a new option is set to choose (to select username form dropdown?), and then use a dropdown with some code to create a list of users? but I'm not sure if that's the whole process that's needed?

    Any advice/input would be appreciated.

    Thanks!

    Posted 12 years ago on Thursday June 14, 2012 | Permalink
  2. Okay, I got the dropdown list of registered users from the site using this forum post, but I can't get the selected user to override the "default author" set in the post title field.

    it's also saving the submitted post as a draft - is there any way to have the post automatically published? (I'm not worried abou non-logged-in users publishing posts willy-nilly, since the form page will not show unless the admin is logged in.)

    Posted 12 years ago on Thursday June 14, 2012 | Permalink
  3. ...and I figured out the "publish automatically" thing through this forum post. So I'm making progress! :)

    So now I'm just stuck on one point. I have a dropdown on my form now that lists all the registered users. But I can't quite sort out how to make the choice override the post author. This is the code I have, but am stuck on:

    add_filter('gform_post_data_2', 'update_post_author'); // "2" in "gform_post_data_2" is the form ID.
    function update_post_author($post_data, $form) {
        $post_data['post_author'] = '???';
        return $post_data;
    }

    I can't sort out what value to place where those question marks go: show to tell that line "shove in whatever value is selected from the dropdown here". Kinda stuck on that point!

    Posted 12 years ago on Thursday June 14, 2012 | Permalink
  4. ...and solved :) I found the documentation for post_data here. The end result was this:

    add_filter('gform_post_data_2', 'update_post_author', 10, 2); // "2" in "gform_post_data_2" is the form ID.
    function update_post_author($post_data, $form) {
        $author_id = rgpost("input_5"); // grab the value from field 5
        $post_data['post_author'] =  $author_id;
        return $post_data;
    }

    Hope that helps someone else!

    Posted 12 years ago on Thursday June 14, 2012 | Permalink
  5. David Peralty

    I had a feeling at your second post that you would figure all of this out pretty quickly. I wish more users would both take it upon themselves to take a look at our documentation and post the solutions they come up with. This thread is great, and I wish we had a "pin to top" because you would have earned it. Besides, I didn't know the answer off the top of my head, and would have had to figure things out around the same time.

    Posted 12 years ago on Thursday June 14, 2012 | Permalink

This topic has been resolved and has been closed to new replies.