gpt4 book ai didi

WordPress 分类术语元不适用于导出和导入

转载 作者:行者123 更新时间:2023-12-03 07:10:14 25 4
gpt4 key购买 nike

我已经为自定义帖子类型创建了一个分类元数据,它在保存、更新、编辑等时工作正常。但在使用 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;
}
?>

我做错了什么?

最佳答案

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

导出自定义帖子类型只会让您在分类 ID 和导出的帖子之间建立联系。要获取该分类法的元数据,请尝试使用此插件,它将为您提供一个 XML,其中包含该分类法的所有其他条目,您也可以导入它

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

您可以在工具 -> Wp Export Cats & Taxs

中找到此内容

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

关于WordPress 分类术语元不适用于导出和导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35572358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com