J'ai fait ce code simple d'ajouter un nouveau poste à WordPress DB (hors LOOP):WordPress - Comment ajouter/mettre à jour post_meta (Custom Fields)?
include_once './wp-config.php';
include_once './wp-load.php';
include_once './wp-includes/wp-db.php';
$upname = 'TestName';
$updescription = 'Description';
// Create post object
$my_post = array();
$my_post['post_title'] = $upname;
$my_post['post_content'] = $updescription;
$my_post['post_status'] = 'draft';
$my_post['post_author'] = 1;
if (current_user_can('manage_options')) {
// Insert the post into the database
wp_insert_post($my_post);
echo '<br /><b>The Advertisement is saved as Draft!</b>';
} else {
echo '<br /><b>You are NOT logged in, login to continue!</b>';
}
Il fonctionne à 100%, mais maintenant je souhaite ajouter deux champs personnalisés: "phone_num" et " date_date "
Comment puis-je ajouter des champs personnalisés dans ce code?
vérifier http://stackoverflow.com/questions/4901544/wp-insert-post-php-function-and-custom-fields –