如何显示自定义帖子类型的自定义字段



我使用了"高级自定义字段";和"自定义帖子类型ui";创建自定义帖子类型和自定义字段的插件。我利用它们,它们为我工作。我创建了一个名为"Videos"的新帖子类型,并打开了它的存档页面,创建了我需要的自定义字段(我只做URL输入),还创建了名为"playlist"的分类法,一切都很顺利。但是现在,当我去到一个视频的单页时,我看不到帖子中的内容,没有URL,没有视频平台名称,没有数据出现。我看不到任何自定义字段。另外,我想为视频设计存档页面。

我用WPBakery页面构建器。我在互联网和youtube上搜索,我找到了使用elements的解决方案,但我没有找到WPBakery的任何解决方案。有人能帮忙吗?

创建自定义post类型的插件代码:

视频发布类型:

function cptui_register_my_cpts() {
/**
* Post Type: Videos.
*/
$labels = [
"name" => __( "Videos", "custom-post-type-ui" ),
"singular_name" => __( "Video", "custom-post-type-ui" ),
"featured_image" => __( "Thumbnail Image", "custom-post-type-ui" ),
"set_featured_image" => __( "Set Thumbnail Image", "custom-post-type-ui" ),
"remove_featured_image" => __( "Remove Thumbnail Image", "custom-post-type-ui" ),
"use_featured_image" => __( "Use Thumbnail Image", "custom-post-type-ui" ),
];
$args = [
"label" => __( "Videos", "custom-post-type-ui" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => true,
"rest_base" => "",
"rest_controller_class" => "WP_REST_Posts_Controller",
"has_archive" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"delete_with_user" => false,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => [ "slug" => "videos", "with_front" => true ],
"query_var" => true,
"menu_icon" => "dashicons-format-video",
"supports" => [ "title", "editor", "thumbnail" ],
"show_in_graphql" => false,
];
register_post_type( "videos", $args );
}
add_action( 'init', 'cptui_register_my_cpts' );

播放列表分类:

function cptui_register_my_taxes_playlist() {
/**
* Taxonomy: Playlists.
*/
$labels = [
"name" => __( "Playlists", "custom-post-type-ui" ),
"singular_name" => __( "Video Playlist", "custom-post-type-ui" ),
];

$args = [
"label" => __( "Playlists", "custom-post-type-ui" ),
"labels" => $labels,
"public" => true,
"publicly_queryable" => true,
"hierarchical" => false,
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => [ 'slug' => 'playlist', 'with_front' => true, ],
"show_admin_column" => false,
"show_in_rest" => true,
"show_tagcloud" => true,
"rest_base" => "playlist",
"rest_controller_class" => "WP_REST_Terms_Controller",
"show_in_quick_edit" => false,
"show_in_graphql" => false,
];
register_taxonomy( "playlist", [ "videos" ], $args );
}
add_action( 'init', 'cptui_register_my_taxes_playlist' );

自定义字段:

if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_615b37c91ca00',
'title' => 'Videos',
'fields' => array(
array(
'key' => 'field_615b37f59afc2',
'label' => 'Video URL',
'name' => 'video_url',
'type' => 'url',
'instructions' => 'insert YouTube url.',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => 'https://youtu.be/******',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'videos',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;      

我认为你需要为视频帖子类型创建一个文件。您可以轻松地创建到您的主题文件夹,名称必须是single-videos.php。单帖子模板代码示例思想分享如下。

<?php
get_header();
?>
<h1><?php the_title(); ?></h1>
<div class="content">
<?php the_content(); ?>
<span><?php the_field('video_url'); ?></span>
</div>
<?php
get_footer();
?>

我希望你能看到你期待的东西。注意:必须为刷新永久链接。

最新更新