Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在插件中使用自定义post类型字段输出_Php_Wordpress_Custom Post Type_Custom Field Type - Fatal编程技术网

Php 如何在插件中使用自定义post类型字段输出

Php 如何在插件中使用自定义post类型字段输出,php,wordpress,custom-post-type,custom-field-type,Php,Wordpress,Custom Post Type,Custom Field Type,如果您有一个自定义的post类型,涉及多个字段,那么您可能希望在插件中使用某个字段的输出。对于自定义帖子类型,只需使用来显示内容。在插件中,这不起作用。没有与自定义帖子类型相关的输出。如何做到这一点 在functions.php中: // Add custom taxonomy for post_type=portfolio function create_portfolio_taxonomies() { // Add new taxonomy, make it hierarchi

如果您有一个自定义的post类型,涉及多个字段,那么您可能希望在插件中使用某个字段的输出。对于自定义帖子类型,只需使用
来显示内容。在插件中,这不起作用。没有与自定义帖子类型相关的输出。如何做到这一点

在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 );

到目前为止,您刚刚在代码中添加的是注册分类法,而不是自定义的post类型。在任何情况下,如果要调用自定义字段的值,可以使用get\u post\u meta()

在这种情况下,它将是:

<?php echo get_post_meta($post->ID,'paragraph_1',true); ?>


我已尝试实现
_字段(“段落_1”)插入插件的代码插件?到底是哪个插件?如何声明自定义字段?字段使用自定义字段,在我上面提到的functions.php中,已编辑。对于插件来说,这有什么区别吗?假设我想在多个插件中使用