首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法重新声明create_post_type() (以前声明过)

无法重新声明create_post_type() (以前声明过)
EN

Stack Overflow用户
提问于 2018-08-31 20:45:09
回答 1查看 1.5K关注 0票数 0

运行两个非常相似的插件在一个wp安装。而当我试图激活一个新的,我得到“不能重新声明以前声明的”错误。错误是指类似的插件之一。但是post类型实际上是不同的(代码如下)。服务器缓存已清除。

新员额类型

代码语言:javascript
复制
function create_post_type() {
  register_post_type( 'Related',
    array(
      'labels' => array(
        'name'               => 'Related',
        'singular_name'      => 'Related Unit',
        'menu_name'          => 'Related Units',
        'name_admin_bar'     => 'Related Unit',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Unit',
        'new_item'           => 'New Unit',
        'edit_item'          => 'Edit Unit',
        'view_item'          => 'View Unit',
        'all_items'          => 'All Units',
        'search_items'       => 'Search Units',
        'parent_item_colon'  => 'Parent Units:',
        'not_found'          => 'No units found.',
        'not_found_in_trash' => 'No units found in Trash.'
      ),
      'public' => true,
      'has_archive' => true,
      'rewrite' => true,
      'hierarchical' => true,
      'supports' => array( 
        'title', 
        'revisions'
    ),
    )
  );
  register_taxonomy("RelatedPlacements", array("Related"), array(
    "hierarchical" => true,
    "label" => "Related Placements",
    "singular_label" => "Related Placement",
    "rewrite" => true
    ));
}

add_action( 'init', 'create_post_type' ); 

有一个错误是指

代码语言:javascript
复制
function create_post_type() {
  register_post_type( 'Ads',
    array(
      'labels' => array(
        'name'               => 'Ads',
        'singular_name'      => 'Ad',
        'menu_name'          => 'Ads',
        'name_admin_bar'     => 'Ad',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Ad',
        'new_item'           => 'New Ad',
        'edit_item'          => 'Edit Ad',
        'view_item'          => 'View Ad',
        'all_items'          => 'All Ads',
        'search_items'       => 'Search Ads',
        'parent_item_colon'  => 'Parent Ads:',
        'not_found'          => 'No ads found.',
        'not_found_in_trash' => 'No ads found in Trash.'
      ),
      'public' => true,
      'has_archive' => true,
      'rewrite' => true,
      'hierarchical' => true,
      'supports' => array( 
        'title', 
        'revisions'
    ),
    )
  );
  register_taxonomy("Placements", array("ads"), array(
    "hierarchical" => true,
    "label" => "Placements",
    "singular_label" => "Placement",
    "rewrite" => true
    ));
}

add_action( 'init', 'create_post_type' );

我只是不明白这些是怎么回事

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-31 20:48:57

您不能在PHP中定义两个名称相同的函数。更改其中一个函数名:

代码语言:javascript
复制
function create_related_post_type() {
   ...
}

add_action( 'init', 'create_related_post_type' );

由于Wordpress的过程代码库和插件冲突的巨大潜力,通常建议在函数的前缀加上一个惟一的名称,比如pluginname_create_post_type

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52122390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档