Not always you want to solve things like WordPress provides and you seek for a different solution. Sometimes you don't need various applications of the backend to publish posts.
A simple example would be a form, no matter where, where the contents of the form should automatically published on your WordPress blog. Alternatively, you could send it with a different status, and therefore only publish them if the admin approves it.
For a good start, here is the function, which is pretty powerful and for all processes of the publication responsible.
wp_insert_post($postarr = array(), $wp_error = false)
You can find a lot information in the Codex of the function.
comment_status [ 'closed' | 'open' ] // 'closed' means no comments. ID [ <post id> ] //Are you updating an existing post? menu_order [ <order> ] //If new post is a page, sets the order should it appear in the tabs, Default is 0 page_template [ <template file> ] //Sets the template for the page. ping_status [ value of default_ping_status ] //Ping status?, Default is empty string pinged [ empty ] //? post_author [ $user_ID ] //The user ID number of the author. post_category [ array(<category id>, <...>) ] //Add some categories. post_content [ <the text of the post> ] //The full text of the post. post_date [ Y-m-d H:i:s ] //The time post was made. post_date_gmt [ Y-m-d H:i:s ] //The time post was made, in GMT. post_excerpt [ <an excerpt> ] //For all your post excerpt needs. post_parent [ <post ID> ] //Sets the parent of the new post, Default is 0 post_password [ empty ] //password for post?, Default is empty string post_status [ 'draft' | 'publish' | 'pending' ] //Set the status of the new post., Default is 'draft' post_title [ <the title> ] //The title of your post. post_type [ 'post' | 'page' ] //Sometimes you want to post a page, Default is 'post'. tags_input [ '<tag>, <tag>, <...>' ] //For tags. to_ping [ whetever ] //Whether to ping.
In the simplest case, you give the contents of the form to the array and it uses this function, which takes care of the processes in WordPress.
To have this function also outside of WordPress available, the functionality of WordPress have to be fetched in this area. If the form is not realized within a template in WordPress, but outside of WP, then you have to implement the file
wp-load.php, for more information read the article „Embed WordPress Functions Outside WordPress“.
require( '../my_wordpress_install_root/wp-load.php' ); // Create post object $my_post = array(); $my_post['post_title'] = 'My post'; $my_post['post_content'] = 'This is my post.'; $my_post['post_status'] = 'publish'; $my_post['post_author'] = 1; $my_post['post_category'] = array(0); // Insert the post into the database wp_insert_post( $my_post );"
This makes a lot of scenarios available and maybe it helps to realize one or other idea.