WordPress分类法术语元不与导出和导入一起使用

时间:2016-02-23 08:26:39

标签: wordpress taxonomy

我为自定义帖子类型创建了分类元数据,并且在保存,更新,编辑等时工作正常。但是在使用wordpress导入器导入或导出时它不起作用。分类法元数据不会导入。

以下是基于Tutorial

的代码
<?php
if ( ! function_exists( 'register_cpt_houses' ) ) {
    function register_cpt_houses() {
        $labels = array(
            'name'              => __('houses', 'my_plugin'),
            'singular_name'     => __('houses', 'my_plugin'),
            'add_new'           => __('Add New','my_plugin'),
            'add_new_item'      => __('Add New Slide','my_plugin'),
            'edit_item'         => __('Edit houses','my_plugin'),
            'new_item'          => __('New houses','my_plugin'),
            'view_item'         => __('View houses','my_plugin'),
            'search_items'      => __('Search houses','my_plugin'),
            'not_found'         => __('No houses found','my_plugin'),
            'not_found_in_trash'=> __('No houses found in Trash','my_plugin'),
            'parent_item_colon' => '' ,
            'all_items' =>  __( 'All houses' ,'my_plugin')
        );

        $args = array(
            'labels'            => $labels,
            'public'            => true,
            'exclude_from_search'=> false,
            'show_ui'           => true,
            'capability_type'   => 'post',
            'hierarchical'      => false,
            'rewrite'           => array('slug'=>'houses', 'with_front' => true ),
            'query_var'         => false,
            'menu_position'     => null,
            'supports'          => array('title', 'thumbnail', 'page-attributes')
        );

        register_post_type('houses',$args);
    }
    add_action('init', 'register_cpt_houses');
}
function register_feature_taxonomy() {
    $labels = array(
        'name' => _x( 'Features', 'taxonomy general name', 'my_plugin' ),
        'singular_name' => _x('Features', 'taxonomy singular name', 'my_plugin'),
        'search_items' => __('Search Feature', 'my_plugin'),
        'popular_items' => __('Common Features', 'my_plugin'),
        'all_items' => __('All Features', 'my_plugin'),
        'edit_item' => __('Edit Feature', 'my_plugin'),
        'update_item' => __('Update Feature', 'my_plugin'),
        'add_new_item' => __('Add new Feature', 'my_plugin'),
        'new_item_name' => __('New Feature:', 'my_plugin'),
        'add_or_remove_items' => __('Remove Feature', 'my_plugin'),
        'choose_from_most_used' => __('Choose from common Feature', 'my_plugin'),
        'not_found' => __('No Feature found.', 'my_plugin'),
        'menu_name' => __('Features', 'my_plugin'),
    );

    $args = array(
        'hierarchical' => false,
        'labels' => $labels,
        'show_ui' => true,
    );

    register_taxonomy('house_feature','houses', $args);
}
add_action( 'house_feature_add_form_fields', 'add_feature_group_field', 10, 2 );
function add_feature_group_field($taxonomy) {
    global $feature_groups;
    ?><div class="form-field term-group">
        <label for="featuret-group"><?php _e('Feature Group', 'my_plugin'); ?></label>
        <select class="postform" id="equipment-group" name="feature-group">
            <option value="-1"><?php _e('none', 'my_plugin'); ?></option><?php foreach ($feature_groups as $_group_key => $_group) : ?>
                <option value="<?php echo $_group_key; ?>" class=""><?php echo $_group; ?></option>
            <?php endforeach; ?>
        </select>
    </div><?php
}
add_action( 'created_house_feature', 'save_feature_meta', 10, 2 );

function save_feature_meta( $term_id, $tt_id ){
    if( isset( $_POST['feature-group'] ) && '' !== $_POST['feature-group'] ){
        $group = sanitize_title( $_POST['feature-group'] );
        add_term_meta( $term_id, 'feature-group', $group, true );
    }
}
add_action( 'house_feature_edit_form_fields', 'edit_feature_group_field', 10, 2 );

function edit_feature_group_field( $term, $taxonomy ){

    global $feature_groups;

    // get current group
    $feature_group = get_term_meta( $term->term_id, 'feature-group', true );

    ?><tr class="form-field term-group-wrap">
        <th scope="row"><label for="feature-group"><?php _e( 'Feature Group', 'my_plugin' ); ?></label></th>
        <td><select class="postform" id="feature-group" name="feature-group">
            <option value="-1"><?php _e( 'none', 'my_plugin' ); ?></option>
            <?php foreach( $feature_groups as $_group_key => $_group ) : ?>
                <option value="<?php echo $_group_key; ?>" <?php selected( $feature_group, $_group_key ); ?>><?php echo $_group; ?></option>
            <?php endforeach; ?>
        </select></td>
    </tr><?php
}
add_action( 'edited_house_feature', 'update_feature_meta', 10, 2 );

function update_feature_meta( $term_id, $tt_id ){

    if( isset( $_POST['feature-group'] ) && '' !== $_POST['feature-group'] ){
        $group = sanitize_title( $_POST['feature-group'] );
        update_term_meta( $term_id, 'feature-group', $group );
    }
}

add_filter('manage_edit-house_feature_columns', 'add_feature_group_column' );

function add_feature_group_column( $columns ){
    $columns['feature_group'] = __( 'Group', 'my_plugin' );
    return $columns;
}
add_filter('manage_house_feature_custom_column', 'add_feature_group_column_content', 10, 3 );

function add_feature_group_column_content( $content, $column_name, $term_id ){
    global $feature_groups;

    if( $column_name !== 'feature_group' ){
        return $content;
    }

    $term_id = absint( $term_id );
    $feature_group = get_term_meta( $term_id, 'feature-group', true );

    if( !empty( $feature_group ) ){
        $content .= esc_attr( $feature_groups[ $feature_group ] );
    }

    return $content;
}
add_filter( 'manage_edit-house_feature_sortable_columns', 'add_feature_group_column_sortable' );

function add_feature_group_column_sortable( $sortable ){
    $sortable[ 'feature_group' ] = 'feature_group';
    return $sortable;
}
?>

我做错了什么?

1 个答案:

答案 0 :(得分:1)

如果您需要在termmeta表中导出数据,请尝试使用此插件将termmeta数据导出到单独的XML文件中。

导出自定义帖子类型只会让您获得分类标识和导出后的连接。 要获取该分类法的元数据,请尝试使用此插件。它将为您提供一个XML,其中包含您可以导入的该分类法的所有其他条目

https://wordpress.org/plugins/wp-export-categories-taxonomies/

您可以在工具中找到它 - &gt; Wp Export Cats&amp;税种税收

选择要导出的自定义帖子类型中的分类法。