我创建了一个外部脚本,将json数据导入到使用wp load的自定义post类型中。php。一切正常,但每次更新后我都会收到消息
Notice: map_meta_cap was called incorrectly. The post type EXAMPLE is not registered, so it may not be reliable to check the capability "edit_post" against a post of that type.
Im调用子主题内的脚本,post\\u type\\u exists返回false,但工作正常。。。
我在一个核心跟踪线程中看到了类似的通知,但它谈到了评论是问题所在,我的帖子类型没有任何评论功能。
function child_post_types() {
$labels = array(
\'name\' => _x( \'Courses\', \'Post Type General Name\', \'test\' ),
\'singular_name\' => _x( \'Course\', \'Post Type Singular Name\', \'test\' ),
\'menu_name\' => __( \'Courses\', \'test\' ),
\'parent_item_colon\' => __( \'Parent Course:\', \'test\' ),
\'all_items\' => __( \'All Courses\', \'test\' ),
\'view_item\' => __( \'View Course\', \'test\' ),
\'add_new_item\' => __( \'Add New Course\', \'test\' ),
\'add_new\' => __( \'Add New\', \'test\' ),
\'edit_item\' => __( \'Edit Course\', \'test\' ),
\'update_item\' => __( \'Update Course\', \'test\' ),
\'search_items\' => __( \'Search Courses\', \'test\' ),
\'not_found\' => __( \'Not found\', \'test\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'test\' ),
);
$args = array(
\'label\' => __( \'Course\', \'test\' ),
\'description\' => __( \'Courses\', \'test\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'thumbnail\', \'editor\', \'revisions\', \'author\' ), //editor, thumbnail, title, author, excerpt, trackpacks, custom-fields, comments, revisions, page-attributes, post-formats
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' =>array(\'slug\'=>\'courses\'),
\'capability_type\' => \'page\',
);
register_post_type( \'course\', $args );
}
add_action( \'init\', \'child_post_types\', 0 );
脚本位于my child主题中,只是获取一个本地json文件,并通过wp\\u update\\u post()循环浏览课程
require(\'../../../wp-load.php\');
$data = json_decode( file_get_contents( \'wp-content/themes/_theme/courses.json\' ), true );
foreach($data as $key => $c){
$course = wp_update_post( array(
\'ID\' => $courseID,
\'post_title\' => $c[\'CourseTitle\'],
\'post_content\' => $c[\'Description\'],
), true );
}
有什么想法吗?