我在函数中注册了以下自定义帖子类型。php和我正在使用Advanced Custom Fields
. 使用高级自定义字段类型,我添加了一个image
字段并分配给我的Release
自定义帖子类型。
现在,我在发布帖子类型中添加了一篇帖子。我已经在这篇文章中填写了这个细节。
Title: 立即发言(豪华版)
Image: 添加了一些图像
现在,我想通过标题/id检索具有特定帖子的元数据。
我尝试过此代码,但不起作用:
$my_post_meta = get_post_meta(556, \'album_image\', true);
if ( ! empty ( $my_post_meta ) ) {
get_field(\'album_image\');
}
My custom post type:
/**
* Music/Releases
*
*/
function codex_custom_init5() {
$labels = array(
\'name\' => \'Releases\',
\'singular_name\' => \'Release\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New Release\',
\'edit_item\' => \'Edit Release\',
\'new_item\' => \'New Release\',
\'all_items\' => \'All Releases\',
\'view_item\' => \'View Release\',
\'search_items\' => \'Search Releases\',
\'not_found\' => \'No release found\',
\'not_found_in_trash\' => \'No release found in Trash\',
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Release\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'release\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
);
register_post_type( \'release\', $args );
}
add_action( \'init\', \'codex_custom_init5\' );