Wordpress 使用元框标题名称和年龄创建自定义帖子类型
需要在Word press中创建带有三个元框标题、名称、代码的自定义帖子类型。我已经熟悉创建自定义帖子类型,但我不想创建图像、描述或任何其他内容。我只需要上面提到的三个字段。有谁能指导我实现这个功能。Wordpress 使用元框标题名称和年龄创建自定义帖子类型,wordpress,custom-post-type,Wordpress,Custom Post Type,需要在Word press中创建带有三个元框标题、名称、代码的自定义帖子类型。我已经熟悉创建自定义帖子类型,但我不想创建图像、描述或任何其他内容。我只需要上面提到的三个字段。有谁能指导我实现这个功能。//这里是您的自定义帖子类型 // Here your Custom Post Type function generate_shows() { $labels = array( 'name' => _x( 'Sho
//这里是您的自定义帖子类型
// Here your Custom Post Type
function generate_shows() {
$labels = array(
'name' => _x( 'Shows', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Show', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Shows', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All Shows', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'add_new_item' => __( 'Add New Show', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'search_items' => __( 'Search Shows', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' )
);
$args = array(
'label' => __( 'enk_show', 'text_domain' ),
'description' => __( 'An individual ENK Shows', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title'),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => true,
'rewrite' => array( 'slug' => 'shows', 'with_front' => 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,
'register_meta_box_cb' => 'add_enk_metaboxes',
'capability_type' => 'post'
);
register_post_type( 'enk_show', $args );
}
// Hook into the 'init' action
add_action( 'init', 'generate_shows', 0 );
add_action( 'admin_init', 'my_admin_samplepost' ); //metabox
function my_admin_samplepost() {
add_meta_box( 'enk_show', 'Details', 'display_samplepost_meta_box','enk_show', 'normal', 'high' ); // add_meta_box enk_show is post type
}
function display_samplepost_meta_box( $samplepost ) {
?>
<h4>Details</h4>
<table width="100%">
<tr>
<td style="width: 25%">Name</td>
<td><input type="text" style="width:425px;" name="meta[nameee]" value="<?php echo esc_html( get_post_meta( $samplepost->ID, 'nameee', true ) );?>" />
</td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" style="width:425px;" name="meta[ageee]" placeholder="$" value="<?php echo esc_html( get_post_meta( $samplepost->ID, 'ageee', true ) );?>" />
</td>
</tr>
</table>
<?php
}
add_action( 'save_post', 'add_samplepost_fields', 10, 2 );
function add_samplepost_fields( $samplepost_id, $samplepost ) {
if ( $samplepost->post_type == 'enk_show' ) { //note please here your post name itherwise your data will not save
if ( isset( $_POST['meta'] ) ) {
foreach( $_POST['meta'] as $key => $value ){
update_post_meta( $samplepost_id, $key, $value );
}
}
}
}
函数generate_shows(){
$labels=数组(
'name'=>\ux('Shows','Post-Type-General-name','text\u-domain'),
'singular_name'=>_x('Show','Post Type singular name','text_domain'),
'menu_name'=>'('Shows','text_domain'),
“父项冒号”=>“(“父项:”,“文本域”),
'all_items'=>'('all Shows','text_domain'),
“查看项目”=>“(“查看项目”、“文本域”),
'add_new_item'=>uuu('add new Show','text_domain'),
'add_new'=>uuu('add new','text_domain'),
“编辑项”=>“(“编辑项”、“文本域”),
'update_item'=>'update item','text_domain'),
“搜索项目”=>“(“搜索显示”、“文本域”),
'not_found'=>'not found','text_domain'),
'not_found_in_trash'=>
);
$args=数组(
'label'=>\('enk\u show','text\u domain'),
'description'=>uuuuu('单个ENK显示','文本域'),
“标签”=>$labels,
'支持'=>数组('title'),
“分类法”=>数组('category','post_标记'),
“分层”=>正确,
“重写”=>array('slug'=>shows','with_front'=>false),
“public”=>正确,
'show_ui'=>true,
“在菜单中显示”=>true,
“在导航菜单中显示”=>true,
“在管理栏中显示”=>true,
“菜单位置”=>5,
“can_export”=>true,
“has_archive”=>true,
“从搜索中排除”=>false,
“公开可查询”=>正确,
“注册元盒”=>“添加元盒”,
“能力类型”=>“职位”
);
注册后类型('enk_show',$args);
}
//钩住“init”操作
添加_操作('init','generate_shows',0);
添加操作('admin_init','my_admin_samplepost')//代谢箱
函数my_admin_samplepost(){
添加元框('enk_show'、'Details'、'display_samplepost_meta_box'、'enk_show'、'normal'、'high');//添加元框enk_show为post类型
}
功能显示\u samplepost\u元\u框($samplepost){
?>
细节
名称
//这里是您的自定义帖子类型
函数generate_shows(){
$labels=数组(
'name'=>\ux('Shows','Post-Type-General-name','text\u-domain'),
'singular_name'=>_x('Show','Post Type singular name','text_domain'),
'menu_name'=>'('Shows','text_domain'),
“父项冒号”=>“(“父项:”,“文本域”),
'all_items'=>'('all Shows','text_domain'),
“查看项目”=>“(“查看项目”、“文本域”),
'add_new_item'=>uuu('add new Show','text_domain'),
'add_new'=>uuu('add new','text_domain'),
“编辑项”=>“(“编辑项”、“文本域”),
'update_item'=>'update item','text_domain'),
“搜索项目”=>“(“搜索显示”、“文本域”),
'not_found'=>'not found','text_domain'),
'not_found_in_trash'=>
);
$args=数组(
'label'=>\('enk\u show','text\u domain'),
'description'=>uuuuu('单个ENK显示','文本域'),
“标签”=>$labels,
'支持'=>数组('title'),
“分类法”=>数组('category','post_标记'),
“分层”=>正确,
“重写”=>array('slug'=>shows','with_front'=>false),
“public”=>正确,
'show_ui'=>true,
“在菜单中显示”=>true,
“在导航菜单中显示”=>true,
“在管理栏中显示”=>true,
“菜单位置”=>5,
“can_export”=>true,
“has_archive”=>true,
“从搜索中排除”=>false,
“公开可查询”=>正确,
“注册元盒”=>“添加元盒”,
“能力类型”=>“职位”
);
注册后类型('enk_show',$args);
}
//钩住“init”操作
添加_操作('init','generate_shows',0);
add_action('admin_init','my_admin_samplepost');//metabox
函数my_admin_samplepost(){
添加元框('enk_show'、'Details'、'display_samplepost_meta_box'、'enk_show'、'normal'、'high');//添加元框enk_show为post类型
}
功能显示\u samplepost\u元\u框($samplepost){
?>
细节
名称
您的答案包含额外的不必要代码。请尝试仅发布所需部分,并在代码中包含一些正确的解释,说明代码的真正作用..!不要只是复制粘贴..!您的答案包含额外的不必要代码。请尝试仅发布所需部分,并在代码中包含一些正确的解释,说明代码的真正作用..!不要只是复制粘贴它。。!