启用了自定义字段的自定义帖子类型,有没有方法设置默认的字段组?

时间:2014-01-15 作者:Toni Michel Caubet

我定义了自定义postype:property,如下所示

function register_cpt_property() {

        $labels = array( 
            \'name\' => _x( \'properties\', \'property\' ),
            \'singular_name\' => _x( \'property\', \'property\' ),
            \'add_new\' => _x( \'Add New\', \'property\' ),
            \'add_new_item\' => _x( \'Add New property\', \'property\' ),
            \'edit_item\' => _x( \'Edit property\', \'property\' ),
            \'new_item\' => _x( \'New property\', \'property\' ),
            \'view_item\' => _x( \'View property\', \'property\' ),
            \'search_items\' => _x( \'Search properties\', \'property\' ),
            \'not_found\' => _x( \'No properties found\', \'property\' ),
            \'not_found_in_trash\' => _x( \'No properties found in Trash\', \'property\' ),
            \'parent_item_colon\' => _x( \'Parent property:\', \'property\' ),
            \'menu_name\' => _x( \'properties\', \'property\' ),
        );

        $args = array( 
            \'labels\' => $labels,
            \'hierarchical\' => false,

            \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'custom-fields\' ),
            \'taxonomies\' => array( \'category\', \'zone\', \'rent\' ),
            \'public\' => true,
            \'show_ui\' => true,
            \'show_in_menu\' => true,


            \'show_in_nav_menus\' => true,
            \'publicly_queryable\' => true,
            \'exclude_from_search\' => false,
            \'has_archive\' => true,
            \'query_var\' => true,
            \'can_export\' => true,
            \'rewrite\' => true,
            \'capability_type\' => \'post\'
        );

        register_post_type( \'property\', $args );
    }
问题是,这将生成此模块:

enter image description here

Wich要求用户使用Wich自定义字段,Wich很棒;但是,有没有办法设置默认组?这个模块最初是这样的?

enter image description here

(我想这样做,这样用户就不会忘记其中的任何一个……但如果他想添加更多,也没关系)

有没有办法做到这一点?

1 个回复
最合适的回答,由SO网友:Abhik 整理而成

元框是您所需要的。

function add_custom_meta_box() {
    add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args );
}
add_action( \'add_meta_boxes\', \'add_custom_meta_box\' );
在第四个参数中设置自定义帖子类型。这应该让您开始:

Custom Meta Box in WordPress Post Pages and Custom Post Type

结束

相关推荐