before我开始,我不使用任何插件为我的CPT和自定义字段。我不想使用这样的插件。
我正在使用几种自定义邮政类型,还包括自定义字段中创建的帖子。由于一些奇怪的原因,在视频下创建的自定义字段将不会被保存。每次我必须用相同的名称创建一个新的自定义字段,并且必须再次添加内容。我无法在下拉列表中选择相应的自定义字段。
自定义字段及其内容存储在Wordpress数据库中,但Wordpress“忘记”当我创建一个新的自定义邮政。
我创建CPT的方式如下:
// Video Custom Post Type
function video_init() {
// set up product labels
$labels = array(
'name' => 'Videos',
'singular_name' => 'Video',
'add_new' => 'Add New Video',
'add_new_item' => 'Add New Video',
'edit_item' => 'Edit Video',
'new_item' => 'New Video',
'all_items' => 'All Videos',
'view_item' => 'View Video',
'search_items' => 'Search Videos',
'not_found' => 'No Videos Found',
'not_found_in_trash' => 'No Videos found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Video',
);
// register post type
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'video'),
'query_var' => true,
'menu_icon' => 'dashicons-video-alt3',
'supports' => array(
'title',
'editor',
'custom-fields',
)
);
register_post_type( 'video', $args );
// register taxonomy
register_taxonomy('video_category', 'video', array('hierarchical' => true, 'label' => 'Category', 'query_var' => true, 'rewrite' => array( 'slug' => 'video-category' )));
}
add_action( 'init', 'video_init' );
?>
然后我将青年链接和副标题纳入我的帖子中。
最后,我将调用CPT,包括它的post元,如下所示
v/deos >
'video' ) ); ?>
have_posts() ) : ?>
have_posts() ) : $query->the_post(); ?>
ID, 'youtubelink', TRUE))=='')) {
echo wp_oembed_get( get_post_meta($post->ID, "youtubelink", true) );
}?>
ID, 'subtitle', true); ?> //////////////////
ID, 'youtubelink', TRUE))=='')) {
echo wp_oembed_get( get_post_meta($post->ID, "youtubelink", true) );
}?>
ID, 'subtitle', true); ?> //////////////////
所以现在,当我创建一个新的视频CPT时,我必须再次创建youtubelink和副标题。这让我很沮丧,因为一切都很完美,只是在这个特定的CPT下,我不知道为什么要一次又一次地创建元字段。
发布于 2018-04-06 19:12:32
默认情况下,post元表单仅限于显示30个键。若要更改该值,请使用postmeta_form_limit
过滤器:
add_filter( 'postmeta_form_limit', function( $limit ) {
return 50;
} );
还可以考虑添加一个自定义元盒,您可以在其中设置专用字段,而不必每次都选择一个键。
https://wordpress.stackexchange.com/questions/300027
复制相似问题