如何在WordPress中将标签添加到类别中?

如何在WordPress中将标签添加到类别中?,wordpress,tags,categories,Wordpress,Tags,Categories,我希望能够按不同字段对类别列表进行排序。我认为标签(或任意字段)是一种很好的方法。但我不知道如何将标签添加到类别中 想法?来自此WordPress StackExchange问答: 这些不是标记,而是保存在wp\u options表中的自定义字段。使用类别ID保存和检索它们,例如,get\u选项(“taxonomy\u$t\u ID”) 检查完整的Q&A以了解其他解决方案。修订守则: add_action( 'category_edit_form_fields', 'extra_edit_tax

我希望能够按不同字段对类别列表进行排序。我认为标签(或任意字段)是一种很好的方法。但我不知道如何将标签添加到类别中


想法?

来自此WordPress StackExchange问答:

这些不是标记,而是保存在
wp\u options
表中的自定义字段。使用类别ID保存和检索它们,例如,
get\u选项(“taxonomy\u$t\u ID”)

检查完整的Q&A以了解其他解决方案。修订守则:

add_action( 'category_edit_form_fields', 'extra_edit_tax_fields_wpse_29322', 15, 2 );
add_action( 'category_add_form_fields', 'extra_add_tax_fields_wpse_29322', 10, 2 );
add_action( 'edited_category', 'save_extra_taxonomy_fields_wpse_29322', 10, 2 );
add_action( 'create_category', 'save_extra_taxonomy_fields_wpse_29322', 10, 2 );   

// Edit existing taxonomy
function extra_edit_tax_fields_wpse_29322( $tag ) 
{
    // Check for existing taxonomy meta for term ID.
    $t_id = $tag->term_id;
    $term_meta = get_option( "taxonomy_$t_id" ); 
    ?>
    <tr class="form-field">
    <th scope="row" valign="top">
        <label for="cat_Image_url"><?php _e( 'Category Navigation Image URL' ); ?></label>
    </th>
        <td>
            <input type="text" name="term_meta[img]" id="term_meta[img]" value="<?php echo esc_attr( $term_meta['img'] ) ? esc_attr( $term_meta['img'] ) : ''; ?>">
            <p class="description"><?php _e( 'Enter the full URL to the navigation image used for this category.' ); ?></p>
        </td>
    </tr>
    <?php
}

// Add taxonomy page
function extra_add_tax_fields_wpse_29322( $tag ) 
{
    ?>
    <div class="form-field">
        <label for="cat_Image_url"><?php _e( 'Category Navigation Image URL' ); ?></label>
        <input type="text" name="term_meta[img]" id="term_meta[img]" value="">
        <p class="description"><?php _e( 'Enter the full URL to the navigation image used for this category.' ); ?></p>
    </div>
    <?php
}

// Save extra taxonomy fields callback function.
function save_extra_taxonomy_fields_wpse_29322( $term_id ) 
{
    if ( isset( $_POST['term_meta'] ) ) 
    {
        $t_id = $term_id;
        $term_meta = get_option( "taxonomy_$t_id" );
        $cat_keys = array_keys( $_POST['term_meta'] );
        foreach ( $cat_keys as $key ) 
        {
            if ( isset ( $_POST['term_meta'][$key] ) )
                $term_meta[$key] = $_POST['term_meta'][$key];
        }
        // Save the option array.
        update_option( "taxonomy_$t_id", $term_meta );
    }
}   
add_action('category_edit_form_fields','extra_edit_tax_fields_wpse_29322;',15,2);
添加操作(“类别添加表单字段”、“额外添加税务字段”wpse 29322',10,2);
添加操作('edited_category'、'save_extra_taxonomy_fields_wpse_29322',10,2);
添加操作('create_category','save_extra_taxonomy_fields_wpse_29322',10,2);
//编辑现有分类法
功能额外编辑税务字段wpse 29322($tag)
{
//检查现有分类法元术语ID。
$t\u id=$tag->term\u id;
$term_meta=get_选项(“分类法_u$t_id”);
?>