-1

I am developing a WordPress theme and there I used a custom post type insurance_all and a custom taxonomy insurnce_all_categories for the post type. But when I try to add a category the AJAX is not working but if I refresh the page the category is loaded. When I want to delete the category An unidentified error has occurred message show me on the top.

My custom post type is

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

My custom taxonomy is

<?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');
1
  • It looks like you've spelt insurance wrong a few times. You've put insurnce at least 3 times for what I can see, fix that first then see what happens. Commented Nov 1, 2017 at 22:31

3 Answers 3

0

Your taxonomy registration in your example is showing this:

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');?>

and needs to be this:

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');?>
0

I faced the same problem in my theme.

Remove extra whitespace in php tag. It may be in php closing tag in functions.php file or any included file.

If you can not find extra whitespace, make a fresh new file and rewrite the code.

Thank you.

-1
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.

1
  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    Commented Apr 19, 2018 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.