如何在自定义帖子分类中添加自定义字段?

时间:2014-07-15 作者:Shihab Malayil

我需要添加一个图像上传字段到我的自定义帖子类型。但它应该在分类法(产品类别)内。如何添加该字段?。

<?php
add_action(\'init\', \'wlg_cstm_register\');  

 function wlg_cstm_register() {  

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

    $product_args = array(  
         \'labels\' => $product_labels,  
         \'public\' => true,  
         \'show_ui\' => true,  
         \'capability_type\' => \'post\',  
         \'hierarchical\' => false,  
         \'rewrite\' => true,
         \'supports\' => array(\'title\', \'editor\', \'thumbnail\'),
        \'taxonomies\' => array( \'\' ),
        \'menu_icon\' => get_bloginfo(\'template_directory\') . \'/resources/img/Products-icon.png\',  // Icon Path
        \'has_archive\' => false       
        );

     register_post_type( \'products\' , $product_args ); 
     register_taxonomy( \'item\', \'products\', array( \'hierarchical\' => true, \'label\' => __(\'Product Category\'), \'query_var\' => \'item\' ) );
 }

1 个回复
SO网友:Bindiya Patoliya

有一个插件http://wordpress.org/extend/plugins/taxonomy-metadata/

向分类法添加自定义元字段需要三个单独的功能:一个是将字段添加到添加新页面;一个用于将字段添加到编辑术语页面;一个用于保存两个页面中自定义字段的值。

您也可以这样编写代码:

https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/

结束

相关推荐