0

如果您有自定义帖子类型,涉及多个字段,您可能希望在插件中使用某个字段的输出。对于自定义帖子类型,您只需使用它<?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 );
4

1 回答 1

0

到目前为止,您刚刚在代码中添加的是注册分类,而不是自定义帖子类型。无论如何,如果要调用自定义字段的值,可以使用 get_post_meta(): http ://codex.wordpress.org/Function_Reference/get_post_meta

在这种情况下,它将是:

<?php echo get_post_meta($post->ID,'paragraph_1',true); ?>
于 2012-10-03T23:12:53.500 回答