1

currently I have a custom post type and a taxonomy as the following :

add_action( 'init', 'create_topics_hierarchical_taxonomy', 0 );
function create_topics_hierarchical_taxonomy() {
  register_taxonomy('type', 'works', array(
        'labels' => array(
            'name'          => 'Types'
        ,   'singular_name' => 'Type'
        ,   'search_items'  => 'Search Types'
        ,   'edit_item'     => 'Edit Type'
        ,   'add_new_item'  => 'Add New Type'
        ),
        'show_ui'               => true,
        'show_admin_column'     => true
    ,   'hierarchical' => true
    ,   'query_var'    => true
    ,   'rewrite'      => array('slug' => 'works/type', 'with_front' => false)
    )); 

}


function custom_post_type() {

    $labels = array(
        'name'                => _x( 'Works', 'Post Type General Name', 'twentyfifteen' ),
        'singular_name'       => _x( 'work', 'Post Type Singular Name', 'twentyfifteen' ),
        'menu_name'           => __( 'Works', 'twentyfifteen' ),
        'parent_item_colon'   => __( 'Parent work', 'twentyfifteen' ),
        'all_items'           => __( 'All Works', 'twentyfifteen' ),
        'view_item'           => __( 'View work', 'twentyfifteen' ),
        'add_new_item'        => __( 'Add New work', 'twentyfifteen' ),
        'add_new'             => __( 'Add New', 'twentyfifteen' ),
        'edit_item'           => __( 'Edit work', 'twentyfifteen' ),
        'update_item'         => __( 'Update work', 'twentyfifteen' ),
        'search_items'        => __( 'Search work', 'twentyfifteen' ),
        'not_found'           => __( 'Not Found', 'twentyfifteen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentyfifteen' ),
    );

// Set other options for Custom Post Type

    $args = array(
        'label'               => __( 'works', 'twentyfifteen' ),
        'description'         => __( 'work news and reviews', 'twentyfifteen' ),
        'labels'              => $labels,
        'taxonomies'         => array('type' ),
        'hierarchical'        => false, 
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => false,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'query_var'             => true,
        'capability_type'     => 'page',
        'rewrite'               => array( 'slug' => 'works' ),
    );

    register_post_type( 'works', $args );

}

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

this enable to browse via :

http://localhost/works/type/testcat/

the needed is

http://localhost/works/testcat/

how I can achieve this ?

thanks in advance.

2
  • Readaing your code, works/testcat/ would be a works post type. Why do you want both taxonomy and post type share the same permalink structure? Not sure if that is possible without some hacking or hardcoding. – cybmeta Feb 25 '17 at 8:13
  • hi, yes the works is a custom post type and type is taxonomy, Im using the type to categorize the works. – Zakari Feb 25 '17 at 10:08

Your Answer

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

Browse other questions tagged or ask your own question.