Wordpress 注册自定义Post类型时,WP_Post对象到字符串转换错误
看到一堆关于帖子ID和菜单的回复。。。但这是一个全新的博客。我正在构建一个插件,但是当我注册一个自定义的帖子类型时,我得到了这个错误 可捕获的致命错误:在第1280行的/WP includes/formatting.php中,类WP_Post的对象无法转换为字符串Wordpress 注册自定义Post类型时,WP_Post对象到字符串转换错误,wordpress,plugins,Wordpress,Plugins,看到一堆关于帖子ID和菜单的回复。。。但这是一个全新的博客。我正在构建一个插件,但是当我注册一个自定义的帖子类型时,我得到了这个错误 可捕获的致命错误:在第1280行的/WP includes/formatting.php中,类WP_Post的对象无法转换为字符串 有人知道可能是什么原因造成的吗?如果我注释掉自定义帖子块。。。然后不会抛出任何错误。通过这种方式注册自定义帖子类型 <?php add_action( 'init', 'my_post_type' );
有人知道可能是什么原因造成的吗?如果我注释掉自定义帖子块。。。然后不会抛出任何错误。通过这种方式注册自定义帖子类型
<?php
add_action( 'init', 'my_post_type' );
function my_post_type() {
register_post_type('car_post', array(
'labels' => array(
'name' => 'Car Content'
),
'singular_label' => 'Car Content',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'show_in_menu' => 'car-post',
'rewrite' => array("slug" => "car_post"),
'supports' => array( 'title', 'editor', 'author', 'revisions', 'comments' )
)
);
}
?>
你所说的自定义帖子块是什么意思?只是指注册自定义帖子类型的代码块。。。只是一次做太多事情的例子。我应该解释得更清楚。它在这里工作得很好。您能展示代码的更多上下文吗?它应该以OP目前的方式工作。:)是的,应该。再说,反正我也有这个动作。它包含在一个函数中。。。
<?php
add_action( 'init', 'my_post_type' );
function my_post_type() {
register_post_type('car_post', array(
'labels' => array(
'name' => 'Car Content'
),
'singular_label' => 'Car Content',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'show_in_menu' => 'car-post',
'rewrite' => array("slug" => "car_post"),
'supports' => array( 'title', 'editor', 'author', 'revisions', 'comments' )
)
);
}
?>