3

I've created a very nice custom post type using the fantastic ACF plugin, but now I need a way for users to submit posts from the front end. Plugins like Gravity forms and Front-end Editor are nice, but don't work very well for this.

Is there a way that I can make the same Back-end edit form show up on a front end page? or alternatively Disguise part of the back-end site to look like the front-end?

Any help would be much apreciated

3 Answers 3

3

Not sure if it would work but have you checked out Scribu's front-end editor?

http://scribu.net/wordpress/front-end-editor

or check this thread

http://wordpress.org/support/topic/front-end-custom-form-to-post?replies=5#post-1584286

1
  • Thanks for the help, but ive already ben through thoses resources and didnt find quite what I want. Is there any way to modify wherer the edit post page appears? Sep 8, 2011 at 23:32
3

What you're asking for is not possible because of the security checks for user capabilities and admin referrer checks. It would be best for you to create a form on the front-end and use the wp_insert_post()

if(isset($_POST['foo_bar'])):

    //Verify nonce and referrer

    //Validate data

    $args = array(
        'post_status' => 'draft',
        'post_content' => esc_html($content),
        'post_title' => esc_attr($title)
    );

    $foo = wp_insert_post($args);

    //If the post was inserted, wp_insert_post() will return the post ID of the new post
    if($foo)
       echo "bar";

endif;

//Create your form with a hidden nonce field here.
  1. You absolutely need to use nonces anytime you accept input.\
  2. Use the built in Wordpress escaping functions to secure input data after you validate it. http://markjaquith.wordpress.com/2009/06/12/escaping-api-updates-for-wordpress-2-8/

I've built several forms like this using a static template as well as an AJAX version. It isn't that hard to do. Just make sure you take every precaution to verify the integrity of the data and hide the input form from evil doers.

4
  • Thank you this is useful information. Is it possible to edit an existing post with a form? Sep 10, 2011 at 19:18
  • Yes, you can use the same basic concept with wp_update_post($args). Just add 'ID' => $post->ID to the $args array. I believe you can even use wp_insert_post as well to do this by supplying the post ID. Sep 11, 2011 at 4:23
  • Great so im off to a good start. My form can now save data to the title, description, and tag fields of a custom post, but my post also has custom fields created with the acf plugin. How can I save fields to a custom post field as well? Sep 12, 2011 at 23:57
  • It's actually very easy. You can use the return post ID value from $foo = wp_insert_post($args); add_post_meta($foo, 'awesome_key', 'awesome_value'); Sep 13, 2011 at 12:32
0

This is now possible with ACF. Just take a look at the documentation to see how to create a front-end form for both creating a new post and editing an existing one. http://www.advancedcustomfields.com/resources/tutorials/creating-a-front-end-form/

Not the answer you're looking for? Browse other questions tagged or ask your own question.