函数自定义帖子类型中的自定义字段无法正常工作
问题描述:
我一直在试图设计新闻作为自定义帖子类型,并且我还将必要的代码添加到了function.php页面。但自定义字段中仍然没有下拉列表。这里是我的代码函数自定义帖子类型中的自定义字段无法正常工作
[![function news_custom_init() {
$args = array(
'public' => true,
'label' => 'News',
'has_archive'=>true,
'supports' => array('title', 'editor', 'description', 'author', 'thumbnail', 'custom-fields')
);
register_post_type('news', $args);
}
add_action('init', 'news_custom_init');
答
这里的添加自定义职位类型的一个基本的例子:
add_action('init', 'create_post_type');
function create_post_type() {
register_post_type('acme_product',
array(
'labels' => array(
'name' => __('News'),
'singular_name' => __('News')
),
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'description', 'author', 'thumbnail', 'custom-fields')
)
);
}
答
function news_custom_init() {
$args = array(
'public' => true,
'labels' => array(
'name' => __('Newss'),
'singular_name' => __('News')
),
'has_archive'=>true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'supports' => array('title', 'editor', 'description', 'author', 'thumbnail', 'custom-fields')
);
register_post_type('news', $args);
}
}
add_action('init', 'news_custom_init');