0

I'm using following code for my custom post type

function resources_custom() {
    $labels = array(
        'name'               => _x( 'Resources', 'post type general name' ),
        'singular_name'      => _x( 'Resources', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'book' ),
        'add_new_item'       => __( 'Add New resources' ),
        'edit_item'          => __( 'Edit Resources' ),
        'new_item'           => __( 'New Resources' ),
        'all_items'          => __( 'All Resources' ),
        'view_item'          => __( 'View Resources' ),
        'search_items'       => __( 'Search resources' ),
        'not_found'          => __( 'No resources found' ),
        'not_found_in_trash' => __( 'No resources found in the Trash' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'Resources'
    );
    $args = array(
        'labels'        => $labels,
        'description'   => 'Holds our products and product specific data',
        'public'        => true,
        'menu_position' => 5,
        'menu_icon' => get_template_directory_uri(). '/images/image-empty.png',
        'supports'      => array( 'title', 'editor', 'thumbnail'),
        'has_archive'   => true,
    );
    register_post_type( 'resources', $args );

}
add_action( 'init', 'resources_custom' );

and use the following code for taxonomies,

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

function create_resources_taxonomies() {
    $labels = array(
        'name'              => _x( 'cat', 'taxonomy general name' ),
        'singular_name'     => _x( 'cat', 'taxonomy singular name' ),
        'search_items'      => __( 'Search category' ),
        'all_items'         => __( 'All category' ),
        '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 Name' ),
        'menu_name'         => __( 'Sections' ),
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'cat',
        'with_front' => true,
        'hierarchical' => true ),
    );

    register_taxonomy( 'genre', array( 'resources' ), $args );
}

Well, my url for custom post archive is : example.com/resources for custom post taxonomies is : example.com/cat/test-taxonomy and for posts is : example.com/resources/test-post

is there any way to use "resources" instead of "cat"? So the custom post taxonomies URL should be like this : example.com/resources/test-taxonomy

3
  • What if a time comes when you have a post and a term with the same slug? WordPress will look for /resources/that-slug and it won't know which to pull up, you can do something like 'slug' => '/resources/cat' or something similar.
    – Howdy_McGee
    Apr 14, 2014 at 18:43
  • it works, what about if i use just resources without cat? it doesn't work for single post type when i changed it to just resources. Apr 14, 2014 at 19:10
  • Nope, you cannot have a taxonomy with the same name as a page. There are a bunch of Q/A that give great responses if you search - here's one I asked awhile back because I agree it is a little confusing.
    – Howdy_McGee
    Apr 14, 2014 at 19:33

0

Your Answer

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

Browse other questions tagged or ask your own question.