删除类别时发生不明错误

时间:2016-10-12 作者:Moshiur Rahman

我正在开发一个WordPress主题,在那里我使用了自定义的帖子类型insurance_all 和自定义分类法insurnce_all_categories 对于职位类型。但是,当我尝试添加一个类别时,AJAX不起作用,但如果我刷新页面,就会加载该类别。当我要删除类别时An unidentified error has occurred 消息显示在顶部。

我的自定义帖子类型为

<?php
$insurnce_all_labels = array(
    \'name\'                  => _x( \'Insurance all \', \'Post Type General Name\', \'safest\' ),
    \'singular_name\'         => _x( \'Insurance all \', \'Post Type Singular Name\', \'safest\' ),
    \'menu_name\'             => __( \'Insurance all\', \'safest\' ),
    \'name_admin_bar\'        => __( \'Insurance all\', \'safest\' ),
    \'archives\'              => __( \'Insurance all Archives\', \'safest\' ),
    \'parent_item_colon\'     => __( \'Insurance all parent item:\', \'safest\' ),
    \'all_items\'             => __( \'Insurance all\' , \'safest\' ),
    \'add_new_item\'          => __( \'Add new item\', \'safest\' ),
    \'add_new\'               => __( \'Add new\', \'safest\' ),
    \'new_item\'              => __( \'Add new item\', \'safest\' ),
    \'edit_item\'             => __( \'Edit item\', \'safest\' ),
    \'update_item\'           => __( \'Update item\', \'safest\' ),
    \'view_item\'             => __( \'View item\', \'safest\' ),
    \'search_items\'          => __( \'Search item\', \'safest\' ),
    \'not_found\'             => __( \'Not found\', \'safest\' ),
    \'not_found_in_trash\'    => __( \'Not found in trash\', \'safest\' ),
    \'insert_into_item\'      => __( \'Insert into item\', \'safest\' ),
    \'uploaded_to_this_item\' => __( \'Uploaded this item to Insurance all section\', \'safest\' ),
    \'items_list\'            => __( \'Insurance all\', \'safest\' ),
    \'items_list_navigation\' => __( \'Insurance all section list navigation\', \'safest\' ),
    \'filter_items_list\'     => __( \'Filter Insurance all section list \', \'safest\' ),
);
$insurnce_all_args = array(
    \'label\'                 => __( \'Insurance all\', \'safest\' ),
    \'description\'           => __( \'Safest Insurance Insurance all for insurance menu\', \'safest\' ),
    \'labels\'                => $insurnce_all_labels,
    \'supports\'              => array(\'title\',\'page-attributes\',\'thumbnail\',\'categories\',),
    \'hierarchical\'          => false,
    \'public\'                => true,
    \'show_ui\'               => true,
    \'menu_position\'         => 8,
    \'menu_icon\'             => \'dashicons-menu\',
    \'show_in_admin_bar\'     => true,
    \'show_in_nav_menus\'     => true,
    \'can_export\'            => true,
    \'has_archive\'           => true,        
    \'exclude_from_search\'   => false,
    \'publicly_queryable\'    => true,
    \'capability_type\'       => \'post\',
);
register_post_type(\'insurance_all\', $insurnce_all_args);
我的自定义分类是

<?php
function insurance_all_category() {
    $labels = array(
        \'name\'              => _x( \'Insurance all category\', \'taxonomy general name\' ),
        \'singular_name\'     => _x( \'Category\', \'taxonomy singular name\' ),
        \'search_items\'      => __( \'Search Category\' ),
        \'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 Category\' ),
        \'menu_name\'         => __( \'Categories\' ),
    );

    register_taxonomy(\'insurnce_all_categories\', array(\'insurance_all\'),$args);
}

add_action(\'init\',\'insurance_all_category\');

3 个回复
SO网友:stims

示例中的分类法注册显示了以下内容:

function insurance_all_category(){
$labels = array(
    \'name\'              =>_x( \'Insurance all category\', \'taxonomy general name\' ),
    \'singular_name\'     => _x( \'Category\', \'taxonomy singular name\' ),
    \'search_items\'      => __( \'Search Category\' ),
    \'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 Category\' ),
    \'menu_name\'         => __( \'Categories\' ),

);

register_taxonomy(\'insurnce_all_categories\', array(\'insurance_all\'),$args);}add_action(\'init\',\'insurance_all_category\');?>
需要这样:

function insurance_all_category(){
$labels = array(
    \'name\'              =>_x( \'Insurance all category\', \'taxonomy general name\' ),
    \'singular_name\'     => _x( \'Category\', \'taxonomy singular name\' ),
    \'search_items\'      => __( \'Search Category\' ),
    \'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 Category\' ),
    \'menu_name\'         => __( \'Categories\' ),

);

//new code
$args = array(
    \'labels\' => $labels
);

register_taxonomy(\'insurnce_all_categories\', array(\'insurance_all\'),$args);}add_action(\'init\',\'insurance_all_category\');?>

SO网友:Joydev Pal

我在主题中也遇到了同样的问题。

删除php标记中的额外空白。它可能位于函数中的php结束标记中。php文件或任何包含的文件。

如果找不到额外的空白,请创建一个新文件并重写代码。

非常感谢。

SO网友:Vivekpathak
function insurance_all_category() {
    $labels = array(
        \'name\'              => _x( \'Insurance all category\', \'taxonomy general name\' ),
        \'singular_name\'     => _x( \'Category\', \'taxonomy singular name\' ),
        \'search_items\'      => __( \'Search Category\' ),
        \'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 Category\' ),
        \'menu_name\'         => __( \'Categories\' ),
    );


    $args = array(

\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array(\'slug\' => \'category\' )

);

    register_taxonomy(\'insurnce_all_categories\', array(\'insurance_all\'),$args);
}

add_action(\'init\',\'insurance_all_category\');

Try this code.

相关推荐

将用户从wp-admin(而不是管理员)重定向

我想重定向除管理员以外的所有用户,使其远离wp admin页面如果登录用户尝试访问/wp admin,则他们将被重定向回主页现在他们看到一个页面,上面写着;抱歉,不允许您访问此页面<你们能帮我在函数中构造一个函数吗。php文件来检查这些条件并重定向<这就是我所拥有的,它并不是为了我想要的。function acme_login_redirect( $redirect_to, $request, $user ) { return ( is_array( $user->role