Nicht immer will man alles so lösen wie es WordPress vorsieht und sucht eine andere Lösung. Nicht selten muss man für diverse Anwendungen das Backend nicht nutzen um Beiträge zu veröffentlichen.
Ein einfaches Beispiel wäre ein Formular, egal wo, mit dem ein Artikel veröffentlicht wird, in dem der Inhalt der Formular an WordPress übertragen wird und automatisch veröffentlicht wird. Alternativ könnte man ihn mit einem anderen Status senden und so erst frei geben, wenn die Redaktion den Artikel frei gibt.
Um nicht bei Null mit der Überlegung zu starten, hier die Funktion die diese Mächtigkeit inne hat und für alle Prozesse der Veröffentlichung verantwortlich ist.
wp_insert_post($postarr = array(), $wp_error = false)
Viele Infos liefert auch der Codex zur Funktion.
Mögliche Parameter $postarr
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.
Beispiel
Im einfachsten Fall übergibt man die Inhalte des Formulars an das Array und dieses nutzt die Funktion, die sich dann um die Prozesse in WordPress kümmert.
Damit die Funktion auch außerhalb von WordPress zur Verfügung steht, muss die Funktionalität von WordPress in diesen Bereich geholt werden. Ist das genannte Formular also nicht mit einem Template in WordPress realisiert, sondern extern von WP, dann muss die Datei wp-load.php
eingebunden werden, siehe Beitrag „WordPress Funktionen außerhalb von WordPress nutzen“.
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 );"
Damit stehen sehr viele Szenarien zur Verfügung und vielleicht hilft dieser kleine Hinweis um die eine oder andere Idee zu verwirklichen.