duanchao1002 2018-09-03 21:38
浏览 59
已采纳

无法为新的自定义帖子类型注册分类

Running 2 function plugins on the same install. One of them registered custom post type and taxonomy for it no problem. Other one, however, doesn't register taxonomy (post type itself is registered no problem).

Here is the code of post type registration for first plugin (where everything works)

/* Ads Custom Post Type */
/*======================*/
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' );

And here is one that doesn't register taxonomy

/* Related Custom Post Type */
/*======================*/
function create_related_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("Collection", array("Related"), array(
    "hierarchical" => true,
    "label" => "Placements",
    "singular_label" => "Placement",
    "rewrite" => true
    ));
   }

   add_action( 'init', 'create_related_post_type' );

Here is error code that i get. Not sure though, if it's related to this issue. Could be related to settings page.

[Mon Sep 03 20:09:55.199466 2018] [proxy_fcgi:error] [pid 26021] [client 127.0.0.1:33527] AH01071: Got error 'PHP message: PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'Related_init' not found or invalid function name in /home/sitedomain/blabla/public_html/wp-includes/class-wp-hook.php on line 286 ', referer: sitedomain/wp-admin/edit.php?post_type=related&page=Related

  • 写回答

1条回答 默认 最新

  • douzheng5717 2018-09-03 23:04
    关注

    From codex:

    Function register post type

    register_post_type( $post_type, $args );
    

    $post_type (string) (required): max. 20 characters, cannot contain capital letters or spaces.

    $args (array) (optional): An array of arguments.


    Function register taxonomy

    register_taxonomy( $taxonomy, $object_type, $args );
    

    $taxonomy (string) (required): The name of the taxonomy. Name should only contain lowercase letters and the underscore character, and not be more than 32 characters long (database structure restriction).

    $object_type (array/string) (required): Name of the object type for the taxonomy object. Object-types can be built-in Post Type or any Custom Post Type that may be registered.

    $args (array) (optional): An array of arguments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型