I have a custom-post type with the standard meta boxes and some custom fields. How could I edit a post through a form in the frontend?
Leave a Reply
You must be logged in to post a comment.
I have a custom-post type with the standard meta boxes and some custom fields. How could I edit a post through a form in the frontend?
You must be logged in to post a comment.
If you want to edit an existing post, try my Front-end Editor plugin.
If you want to create new posts, try one of these:
Here is a basic solutions for updating a post/page. I added a quick demo of custom meta fields. This is pretty basic, but will point you in the direction of plugin-less editing of posts on the front-end. This isn’t super flexible, but you can add whatever you need to it.
Add this code into your loop:
Then add this code at the top of the page to process the form:
I use Advanced Custom Fields for lots of front end post editing with meta boxes. ACF allows you to build lots of advanced meta box fields and adds them automatically to the back end post panel.
But there is a front end function as well.
This method is completely free. The only way it costs anything is if you want to use any of their more complex field type add-ons like repeater, flexible, or gallery. Which all work great here.
The first drawback is that it doesn’t include the post title and description… but that can be fixed pretty easily by adding this to your functions.php:
That will add all the code to support a title and content field that can be added to the front end forms like this:
I use this method on most of the sites I work on these days. I tend to use Gravity Forms to create a basic post and then I control everything with ACF on the front and back end. The best thing is that you manage it all from one place for both. It is worth noting, however, that ACF can be used to create a post as well. I haven’t used it, but will be giving it a try on my next project, so that I can create with full meta access.
ACF is, personally, the only plugin I can’t live without with Gravity Forms as a close second.
The easiest way would be to use something like Ninja Forms with the following paid extension:
http://wpninjas.com/downloads/front-end-posting/
You could also code this yourself. Essentially you’ll create a form, and then use
wp_insert_post()
to create a full post.A sample form:
and then on submit, you’d save process it something like:
The full code and tutorial is from:
http://wp.tutsplus.com/tutorials/creative-coding/posting-via-the-front-end-inserting/