WordPress front-end post form using wp_insert_post
(I was leading a session on wp_insert_post() at the time, the slides for which you can find here.)
If you’re not aware, we recently launched a featured on Android and Me called Threads. Threads allow users with enough points (oh yeah, our blog runs on a point system, too- take notes!) to create a post directly from the front-end of the site, never seeing /wp-admin. While my production implementation is quite a bit more complex than this, below I’ve shared a stripped down version of the functionality. Join me at the bottom for some extra, dirty details.
If you’d like to see a preview of the whole thing, go create an account on Android and Me, toil through the ranks, earn some influence, then make a thread. Orrrr, you can check out a preview over on Forrst. I’d love to show you the live page, but it really is for power-users only. In the preview you’ll also notice we’re doing some neat things like charging for creating threads and using a custom editor via MarkItUp, but I left out all that stuff in the above example. The finesse is up to your imagination.
Along with the above snippet, please go study the wp_insert_post() codex page. There, you’ll find all the arguments and settings you’ll need to insert just about any damn post you can imagine. Any post type, any author, with any meta, from anywhere on your site. Think about that.
PS: I haven’t tested the above stripped-down snippet by itself, so take it with a grain of salt. Use it as a springboard, not a copy & paste solution.
PPS: The above snippet can also be found on Gist, ripe for forking.
DATE24th May, 2012