如何将自定义字段添加到自定义帖子类型? [英] How to add custom field to custom post type?

查看:15
本文介绍了如何将自定义字段添加到自定义帖子类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好。

我已经创建了一个名为‘Products’的自定义帖子类型。我想创建自定义字段(是元数据 正确的术语是什么?)在这里,我的客户可以勾选一个框,以确定此列表中的给定帖子 CPT是一篇专题帖子。

以下是我的函数.php中用于创建‘Products’CPT的代码:

function products_custom_init() {

    $labels = array(
        'name' => _x('Products', 'post type general name'),
        'singular_name' => _x('Product', 'post type singular name'),
        'add_new' => _x('Add New', 'products'),
        'add_new_item' => __('Add New Product'),
        'edit_item' => __('Edit Product'),
        'new_item' => __('New Product'),
        'view_item' => __('View Product'),
        'search_items' => __('Search Products'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => false,
        'query_var' => true,
        'rewrite' => array('slug','pages'),
        'capability_type' => 'post',
        'hierarchical' => true,
        'menu_position' => 5,
        'supports' => array('title','editor','thumbnail','excerpt',)
      );

    register_post_type( 'products' , $args );
}
add_action( 'init', 'products_custom_init' );

那么我如何向OnlyProducts帖子中添加‘Feed’Metabox/Customer字段?

非常感谢,

辛西娅

推荐答案

您可以使用此插件

http://wordpress.org/extend/plugins/types/

或本教程可能对您有所帮助。

http://wptheming.com/2010/08/custom-metabox-for-post-type/

这篇关于如何将自定义字段添加到自定义帖子类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆