繁体   English   中英

将自定义Wordpress编辑器提交到wp-admin / post.php

[英]Submit custom Wordpress Editor to wp-admin/post.php

我正在尝试在自定义主题页面上使用工作中的帖子编辑器。 编辑器本身可以工作(使用wp_editor() ),但是如果我将action="/wp-admin/post.php"到表单和以下隐藏字段中:

_wpnoncewp_create_nonce() ), post_typeoriginalactionpost_author ,... post.php页面说Are you sure you want to do this? 如果我只发送内容,我将被重定向到wp-admin/edit.php但没有创建帖子...

所以我的问题是; 是否可以使自定义wordpress编辑器提交到现有的wp-admin / post.php,还是我必须自己捕获内容并上传并通过PHP创建帖子?

我找到了一个解决方案,并按以下步骤解决了该问题:表单以主题的主页为目标,并且在我的functions.php手动处理了表单数据(当然index.php也可以工作):

$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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM