I'm trying to get a working post editor on a custom theme page. The editor itself works (using wp_editor()
), but If I add action="/wp-admin/post.php"
to the form and the following hidden fields:
_wpnonce
( wp_create_nonce()
), post_type
, originalaction
, post_author
, ... the post.php page says Are you sure you want to do this?
. If I only send the content I'm being redirect to wp-admin/edit.php
but no post is being created...
So my question is; is it possible to make a custom wordpress editor submitting to the existing wp-admin/post.php, or do I have to catch the content and uploads and create the post via PHP myself?
I found a solution and solved it as following: The form targets my theme's main page, and I handled the form data manually in my functions.php
( index.php
would of course work as well):
$post_options = array(
'post_title' => wp_strip_all_tags($_POST['post_title']),
'post_content' => $_POST['post_content'],
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_category' => []
);
$new_post = wp_insert_post($post_options);
if (!is_wp_error($new_post)) {
// success
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.