我正在将信息插入新帖子,当我使用 var_dump 时,我没有看到任何作者 ID,因此,我以后无法检索它。
global $user_ID;
$new_post = array(
'post_title' => $_POST['titulo_necessidade'],
'post_content' => $_POST['conteudo_necessidade'],
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'necessidade',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);
var_dump(get_post_meta($post_id));
我得到的结果如下
array(3) { ["titulo_necessidade"]=> array(1) { [0]=> string(7) "tyktyuk"} ["conteudo_necessidade"]=> array(1) { [0]=> string(7) "tkyutut"} ["submit_necessidade"]=> array(1) { [0]=> string(6) "Enviar"} }
最佳答案
在注册自定义帖子类型 register_post_type
时检查您是否指定支持的 author
。
有关自定义帖子类型的更多信息:http://codex.wordpress.org/Function_Reference/post_type_supports
关于wordpress - 没有作者的自定义帖子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16193978/