如果您有自定义帖子类型,涉及多个字段,您可能希望在插件中使用某个字段的输出。对于自定义帖子类型,您只需使用它<?php the_field('paragraph_1'); ?>
来显示内容。在插件中,这不起作用。没有与自定义帖子类型相关的输出。如何实现?
在functions.php中:
// Add custom taxonomy for post_type=portfolio
function create_portfolio_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Portfolio Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Genre Category' ),
'menu_name' => __( 'Category' ),
);
register_taxonomy('work-category',array('portfolio'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'work-category' ),
));
}
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_portfolio_taxonomies', 0 );