Support Forum
Support › Meta Box AIO › Post type and taxonomy not connected when copying php codeResolved
I created a post type "messages" and a taxonomy "topics".
When I create a new "Message" I can choose the topic (like a post category, not a tag!).
When I copy the php code from the post type "messages" and "topics" and turn this into a plug-in or add this to the functions.php of the theme a strange thing happens.
When I create a new message, the box for the topics is there, but I can't choose anything.
I double checked the generated code.
What am I doing wrong or what should I change ?
Hi,
Thank you for reaching out.
After adding the generated PHP code to the file functions.php in a plugin or the theme, did you deactivate the extension MB Custom Post Types or move the post type Message to Trash in the Builder?
You can also share the generated PHP code, I will help you to check it on my end.
I de-activated the Metabox Custom Post type plug-in.
The code I generated for the post type and taxanomy is this:
<?php
add_action( 'init', 'ivanit_messages' );
function ivanit_messages() {
$labels = [
'name' => esc_html__( 'Messages', 'ivanit-messages' ),
'singular_name' => esc_html__( 'Message', 'ivanit-messages' ),
'add_new' => esc_html__( 'Add New', 'ivanit-messages' ),
'add_new_item' => esc_html__( 'Add new message', 'ivanit-messages' ),
'edit_item' => esc_html__( 'Edit Message', 'ivanit-messages' ),
'new_item' => esc_html__( 'New Message', 'ivanit-messages' ),
'view_item' => esc_html__( 'View Message', 'ivanit-messages' ),
'view_items' => esc_html__( 'View Messages', 'ivanit-messages' ),
'search_items' => esc_html__( 'Search Messages', 'ivanit-messages' ),
'not_found' => esc_html__( 'No messages found', 'ivanit-messages' ),
'not_found_in_trash' => esc_html__( 'No messages found in Trash', 'ivanit-messages' ),
'parent_item_colon' => esc_html__( 'Parent Message:', 'ivanit-messages' ),
'all_items' => esc_html__( 'All Messages', 'ivanit-messages' ),
'archives' => esc_html__( 'Message Archives', 'ivanit-messages' ),
'attributes' => esc_html__( 'Message Attributes', 'ivanit-messages' ),
'insert_into_item' => esc_html__( 'Insert into message', 'ivanit-messages' ),
'uploaded_to_this_item' => esc_html__( 'Uploaded to this message', 'ivanit-messages' ),
'featured_image' => esc_html__( 'Featured image', 'ivanit-messages' ),
'set_featured_image' => esc_html__( 'Set featured image', 'ivanit-messages' ),
'remove_featured_image' => esc_html__( 'Remove featured image', 'ivanit-messages' ),
'use_featured_image' => esc_html__( 'Use as featured image', 'ivanit-messages' ),
'menu_name' => esc_html__( 'Messages', 'ivanit-messages' ),
'filter_items_list' => esc_html__( 'Filter messages list', 'ivanit-messages' ),
'filter_by_date' => esc_html__( '', 'ivanit-messages' ),
'items_list_navigation' => esc_html__( 'Messages list navigation', 'ivanit-messages' ),
'items_list' => esc_html__( 'Messages list', 'ivanit-messages' ),
'item_published' => esc_html__( 'Message published', 'ivanit-messages' ),
'item_published_privately' => esc_html__( 'Message published privately', 'ivanit-messages' ),
'item_reverted_to_draft' => esc_html__( 'Message reverted to draft', 'ivanit-messages' ),
'item_scheduled' => esc_html__( 'Message scheduled', 'ivanit-messages' ),
'item_updated' => esc_html__( 'Message updated', 'ivanit-messages' ),
'text_domain' => esc_html__( 'ivanit-messages', 'ivanit-messages' ),
];
$args = [
'label' => esc_html__( 'Messages', 'ivanit-messages' ),
'labels' => $labels,
'description' => '',
'public' => true,
'hierarchical' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'show_in_rest' => true,
'query_var' => true,
'can_export' => true,
'delete_with_user' => true,
'has_archive' => true,
'rest_base' => '',
'show_in_menu' => true,
'menu_icon' => 'dashicons-admin-home',
'menu_position' => '',
'capability_type' => 'post',
'supports' => ['title', 'editor', 'thumbnail'],
'taxonomies' => ['topic'],
'rewrite' => [
'with_front' => false,
],
];
register_post_type( 'message', $args );
}
add_action( 'init', 'ivanit_topics' );
function ivanit_topics() {
$labels = [
'name' => esc_html__( 'Topics', 'ivanit-topics' ),
'singular_name' => esc_html__( 'Topic', 'ivanit-topics' ),
'menu_name' => esc_html__( 'Topics', 'ivanit-topics' ),
'search_items' => esc_html__( 'Search Topics', 'ivanit-topics' ),
'popular_items' => esc_html__( 'Popular Topics', 'ivanit-topics' ),
'all_items' => esc_html__( 'All Topics', 'ivanit-topics' ),
'parent_item' => esc_html__( 'Parent Topic', 'ivanit-topics' ),
'parent_item_colon' => esc_html__( 'Parent Topic', 'ivanit-topics' ),
'edit_item' => esc_html__( 'Edit Topic', 'ivanit-topics' ),
'view_item' => esc_html__( 'View Topic', 'ivanit-topics' ),
'update_item' => esc_html__( 'Update Topic', 'ivanit-topics' ),
'add_new_item' => esc_html__( 'Add new topic', 'ivanit-topics' ),
'new_item_name' => esc_html__( 'New topic name', 'ivanit-topics' ),
'separate_items_with_commas' => esc_html__( 'Separate topics with commas', 'ivanit-topics' ),
'add_or_remove_items' => esc_html__( 'Add or remove topics', 'ivanit-topics' ),
'choose_from_most_used' => esc_html__( 'Choose most used topics', 'ivanit-topics' ),
'not_found' => esc_html__( 'No topics found', 'ivanit-topics' ),
'no_terms' => esc_html__( 'No Topics', 'ivanit-topics' ),
'filter_by_item' => esc_html__( 'Filter by topic', 'ivanit-topics' ),
'items_list_navigation' => esc_html__( 'Topics list pagination', 'ivanit-topics' ),
'items_list' => esc_html__( 'Topics list', 'ivanit-topics' ),
'most_used' => esc_html__( 'Most Used', 'ivanit-topics' ),
'back_to_items' => esc_html__( 'Back to topics', 'ivanit-topics' ),
'text_domain' => esc_html__( 'ivanit-topics', 'ivanit-topics' ),
];
$args = [
'label' => esc_html__( 'Topics', 'ivanit-topics' ),
'labels' => $labels,
'description' => '',
'public' => true,
'publicly_queryable' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'meta_box_cb' => true,
'show_in_rest' => true,
'show_tagcloud' => true,
'show_in_quick_edit' => true,
'show_admin_column' => false,
'query_var' => true,
'sort' => false,
'rest_base' => '',
'rewrite' => [
'with_front' => false,
'hierarchical' => false,
],
];
register_taxonomy( 'topic', ['message'], $args );
}
?>
Thank you for your help.
Hi,
The issue looks to relate to this topic https://support.metabox.io/topic/unable-to-edit-taxonomies-in-editor/
Please follow the topic and let me know if it helped.
That was exactly the problem and solution I was looking for.
Thank you!