这是一种添加post图像和其他内容的方法。因此,根据您的需要对其进行不同的检查。
<?php
if( \'POST\' == $_SERVER[\'REQUEST_METHOD\' ] && !empty( $_POST[\'action\' ] ) && $_POST[\'action\' ] == "new_post") {
if (isset ($_POST[\'post_title\'])) {
$post_title = $_POST[\'post_title\'];
}
$post = array(
\'post_title\' => $post_title,
\'post_content\' => $post_content,
\'post_category\' => array($post_category),
\'tags_input\' => array($post_tags),
\'post_status\' => \'draft\',
\'post_type\' => \'post\'
);
$post_id = wp_insert_post($post);
wp_set_post_tags($post_id, $post_tags);
if (!empty($_FILES[\'file_0\'][\'name\'])) {
foreach ($_FILES as $file_id => $array) {
$attachment_id = insert_attachment($file_id,$post_id,true);
}
//send_mail_on_post_submit($userEmail);
$success = __(\'This post is awaiting approval by the moderators\', \'frontendprofile\');
}
unset($_POST);
}
?>