0

I'm having a hard time explaining this, so bare with me.

Category and tag links for my custom post type aren't working as I expected them to. Instead of getting http://www.example.com/projects/category/example-category, the links that are http://www.example.com/category/example-category. In other words, I can't figure out how to make my categories post-type specific. In the dashboard, my Projects post type has both a Tags and a Categories section, but editing them results in the same changes being made to the main Posts post type.

How can I create post-type specific categories?

Here's my code to create the post type:

function projects_create_post_type() {
    $labels = array(
        "add_new" => "Add New",
        "add_new_item" => "Add New",
        "all_items" => "All Projets",
        "edit_item" => "Edit",
        "menu_name" => "Projects",
        "name" => "Projects",
        "new_item" => "New",
        "not_found" =>  "No projects found",
        "not_found_in_trash" => "No projects found in Trash",
        "search_items" => "Search Projects",
        "singular_name" => "Project",
        "view_item" => "View",
    );
    $args = array(
        "has_archive" => true,
        "hierarchical" => false,
        "labels" => $labels,
        "menu_icon" => __("dashicons-hammer"),
        "menu_position" => 5,
        "public" => true,
        "slug" => "projects",
        "supports" => array(
            "editor",
            "thumbnail",
            "title",
        ),
        "taxonomies" => array("post_tag", "category"),
    );
    register_post_type("projects", $args);
}
add_action("init", "projects_create_post_type");
2

You need to create taxonomies specific to your post type using register_taxonomy instead of using the taxonomies argument when registering the post type.

http://codex.wordpress.org/Function_Reference/register_taxonomy

// categories
register_taxonomy(
  'project_categories',
  'projects',
  array(
    'label'        => __( 'Categories' ),
    'rewrite'      => false,
    'hierarchical' => true,
    'capabilities' => array( 'edit_terms' => 'manage_categories' )
  )
);

// tags
register_taxonomy(
  'project_tags',
  'projects',
  array(
    'label'        => __( 'Tags' ),
    'rewrite'      => false,
    'hierarchical' => false,
    'capabilities' => array( 'edit_terms' => 'manage_categories' )
  )
);

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.