0

I am currently developing my own travel website/blog. I would like to add "hotels" and "tips and tricks" to this website. I have made two custom post types that use the default post categories as a taxonomy (as shown below). I haven't bothered making custom taxonomies, as it would triple my work load, since I would just have to copy all the data from the default categories.

register_post_type('hotels', 
        array(  'taxonomies'            => array('category'),
                'labels'                => array(
                    'name'                  => __('Hotels'),
                    'singular_name'         => __('Hotel'),
                    'add_new'               => __('Add new hotel'),
                    'edit_item'             => __('Edit hotel'),
                    'new_item'              => __('New hotel'),
                    'view_item'             => __('View hotel'),
                    'search_items'          => __('Search hotels'),
                    'not_found'             => __('No hotels found'),
                    'not_found_in_trash'    => __('No hotels found in trash')
                ),

                'has_archive'           => true,
                'hierarchical'          => true,
                'public'                => true,
                'supports'              => array('title', 'editor', 'post-formats')
    ));

Now, there are two things that I can't seem to achieve.

  1. Get the link of a category (for example: Mexico) that only shows a custom post type and not my default posts. (e.g. I would want to see the hotels in Mexico)
  2. Get an option in the admin-section (menu) that allows me to add said link to the menu.

Any help would be greatly appreciated.

3
  • If you don't see your taxonomy, check under the Screen Options tab in the upper-right corner of the admin window and make sure the Show on screen check box is ticked for that taxonomy. Jan 23, 2018 at 11:16
  • I am not using a custom taxonomy, taht's the entire thing. I am using the default category taxonomy that is also used in posts. The data for my categories and my custom taxonomies would be entirely the same, so I am trying to use just the default category taxonomy. The only issue I'm facing there, is that I can't get the category page for the custom post types, only for default posts. Jan 23, 2018 at 11:31
  • Have you checked out wordpress.stackexchange.com/questions/43395/…?
    – swissspidy
    Jan 23, 2018 at 11:50

1 Answer 1

0

try this, I believe this should allow you to have category taxonomy in menu and available in your custom post type.

function custom_post_type() {

    $labels = array(
        'name'                  => _x( 'Post Types', 'Post Type General Name', 'text_domain' ),
        'singular_name'         => _x( 'hotel', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'             => __( 'Post Types', 'text_domain' ),
        'name_admin_bar'        => __( 'Post Type', 'text_domain' ),
        'archives'              => __( 'Item Archives', 'text_domain' ),
        'attributes'            => __( 'Item Attributes', 'text_domain' ),
        'parent_item_colon'     => __( 'Parent Item:', 'text_domain' ),
        'all_items'             => __( 'All Items', 'text_domain' ),
        'add_new_item'          => __( 'Add New Item', 'text_domain' ),
        'add_new'               => __( 'Add New', 'text_domain' ),
        'new_item'              => __( 'New Item', 'text_domain' ),
        'edit_item'             => __( 'Edit Item', 'text_domain' ),
        'update_item'           => __( 'Update Item', 'text_domain' ),
        'view_item'             => __( 'View Item', 'text_domain' ),
        'view_items'            => __( 'View Items', 'text_domain' ),
        'search_items'          => __( 'Search Item', 'text_domain' ),
        'not_found'             => __( 'Not found', 'text_domain' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
        'featured_image'        => __( 'Featured Image', 'text_domain' ),
        'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
        'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
        'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
        'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
        'items_list'            => __( 'Items list', 'text_domain' ),
        'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
        'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
    );
    $args = array(
        'label'                 => __( 'hotel', 'text_domain' ),
        'description'           => __( 'Post Type Description', 'text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'post-formats' ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        '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'       => 'page',
    );
    register_post_type( 'hotels', $args );

}
add_action( 'init', 'custom_post_type', 0 );

Your Answer

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

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