2

After I select terms and then save my custom post type, new taxonomy terms are generated with integer values and selected every time. I don't know what the problem is, nor have I found any sort of the same issue anywhere on the internet. Here is a picture of what exactly is going on: http://prntscr.com/fvfqvf

Registering Post Type

function tbs_register_post_type() {
    $singular = 'Stylist';
    $plural = 'Stylists';

    $labels = array(
        'name' => $plural,
        'singular_name' => $singular,
        'add_new' => 'Add New',
        'add_new_item' => 'Add New ' . $singular,
        'edit_item' => 'Edit ' . $singular,
        'new_item' => 'New ' . $singular,
        'view_item' => 'View ' . $singular,
        'view_items' => 'View ' . $plural,
        'search_items' => 'Search ' . $plural,
        'not_found' => 'No ' . strtolower($plural) . ' found',
        'not_found_in_trash' => 'No ' . strtolower($plural) . ' found in trash',
        'all_items' => 'All ' . $plural,
        'archives' => $singular . ' Archives',
        'attributes' => $singular . ' Attributes',
        'insert_into_item' => 'Insert into ' . strtolower($singular),
        'uploaded_to_this_item' => 'Uploaded to this ' . strtolower($singular),
        'featured_image' => $singular . ' Picture',
        'set_featured_image' => 'Set ' . strtolower($singular) . ' picture',
        'remove_featured_image' => 'Remove ' . strtolower($singular) . ' picture',
        'use_featured_image' => 'Use as ' . strtolower($singular) . ' picture',
        'filter_items_list' => 'Filter ' . strtolower($plural) . ' list',
        'items_list_navigation' => $plural . ' list navigation',
        'items_list' => $plural . ' list'
    );

    $args = array(
        'label' => $plural,
        'labels' => $labels,
        'description' => 'A custom plugin to create, edit, and delete stylists made for -.',
        'public' => true,
        'menu_position' => '2',
        'menu_icon' => 'dashicons-groups',
        'supports' => array('title', 'thumbnail'),
        'taxonomies' => array('tbs_skills', 'tbs_fun_facts'),
        'has_archive' => false,
        'rewrite' => array('slug' => 'stylists')
    );

    register_post_type('tbs_stylists', $args);
}
add_action('init', 'tbs_register_post_type');

Registering Taxonomies

function tbs_register_skills_taxonomy() {
    $singular = 'Skill';
    $plural = 'Skills';

    $labels = array(
        'name' => $plural,
        'singular_name' => $singular,
        'all_items' => _('All '. $plural),
        'edit_item' => _('Edit ' . $singular),
        'view_item' => _('View ' . $singular),
        'update_item' => _('Update ' . $singular),
        'add_new_item' => _('Add New ' . $singular),
        'new_item_name' => _('New ' . $singular . ' Name'),
        'search_items' => _('Search ' . $plural),
        'popular_items' => _('Popular ' . $plural),
        'separate_items_with_commas' => _('Separate ' . strtolower($plural) . ' with commas'),
        'add_or_remove_items' => _('Add or remove ' . strtolower($plural)),
        'choose_from_most_used' => _('Choose from the most common ' . strtolower($plural)),
        'not_found' => _('No ' . strtolower($plural) . ' found.')
    );

    $args = array(
        'label' => $plural,
        'labels' => $labels,
        'description' => 'A custom taxonomy for the stylists custom post type made for -.',
        'public' => true
    );

    register_taxonomy('tbs_skills', 'tbs_stylists', $args);
}
add_action('init', 'tbs_register_skills_taxonomy');

function tbs_register_fun_facts_taxonomy() {
    $singular = 'Fun Fact';
    $plural = 'Fun Facts';

    $labels = array(
        'name' => $plural,
        'singular_name' => $singular,
        'all_items' => _('All '. $plural),
        'edit_item' => _('Edit ' . $singular),
        'view_item' => _('View ' . $singular),
        'update_item' => _('Update ' . $singular),
        'add_new_item' => _('Add New ' . $singular),
        'new_item_name' => _('New ' . $singular . ' Name'),
        'search_items' => _('Search ' . $plural),
        'popular_items' => _('Popular ' . $plural),
        'separate_items_with_commas' => _('Separate ' . strtolower($plural) . ' with commas'),
        'add_or_remove_items' => _('Add or remove ' . strtolower($plural)),
        'choose_from_most_used' => _('Choose from the most common ' . strtolower($plural)),
        'not_found' => _('No ' . strtolower($plural) . ' found.')
    );

    $args = array(
        'label' => $plural,
        'labels' => $labels,
        'description' => 'A custom taxonomy for the stylists custom post type made for -.',
        'public' => true
    );

    register_taxonomy('tbs_fun_facts', 'tbs_stylists', $args);
}
add_action('init', 'tbs_register_fun_facts_taxonomy');

Editing Post Page Functions

function tbs_change_title_text($title){
    $screen = get_current_screen();
    if ('tbs_stylists' == $screen->post_type) $title = 'Enter stylist name';
    return $title;
}
add_filter('enter_title_here', 'tbs_change_title_text');

function tbs_move_metas() {
    remove_meta_box('tagsdiv-tbs_skills', 'tbs_stylists', 'side');
    add_meta_box('tagsdiv-tbs_skills', 'Skills', 'post_categories_meta_box', 'tbs_stylists', 'normal', 'high', array('taxonomy' => 'tbs_skills'));

    remove_meta_box('tagsdiv-tbs_fun_facts', 'tbs_stylists', 'side');
    add_meta_box('tagsdiv-tbs_fun_facts', 'Fun Facts', 'post_categories_meta_box', 'tbs_stylists', 'normal', 'high', array('taxonomy' => 'tbs_fun_facts'));
}
add_action('admin_init', 'tbs_move_metas');

If anyone could offer some insight I would appreciate it. Thank you.

  • I already kind of knew this but never included it in the initial post: It seems as if removing the meta boxes from the side and adding them into the normal screen is what brings about this problem. – George Edward Shaw IV Jul 14 '17 at 1:37
0

This appears to be a result of the conflict between declaring a non-hierarchical custom taxonomy, and using the post_categories_meta_box (checkboxes) as an interface.

You could call the discrepancy a bug in WP Core, certainly the fact that the conflict is allowed in the taxonomy declaration itself.

The problem seems to be that for your non-hierarchical taxonomy, the checkboxes are rendered with the input "value" = term_id, but the checkbox callback used at post save time stores the value of the checked item as a term name, so you get that integer (the ID) created and stored as a "new" term.

See also this question

Solution for now: just declare the taxonomy as hierarchical if you want to use the checkbox interface.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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