Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type called 'designs' and have registered taxonomy 'design_category' and 'design_tag'.

I'm trying to get the permalinks as follows but not having much luck - seems having 2 taxonommies is causing only one to work - either 'design_category' or 'design_tag'

I want the permalinks like this:

a single design: url.com/designs/design_category/single-design

a design category: url.com/designs/design_category

a design tag: url.com/designs/design_tag

there are only a few specific categories and not much room for expansion there so there won't ever be a matching category and tag.

this is the code I have to create everything - just stuck on getting the tags to work - keeps going to 404 error :(

function create_design() {
  // Design Tags
  $labels = array(
'name' => _x( 'Design Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Design Tag', 'taxonomy singular name' ),
'search_items' =>  __( 'Search Design Tags' ),
'all_items' => __( 'All Design Tags' ),
'parent_item' => __( 'Parent Design Tags' ),
'parent_item_colon' => __( 'Parent Design Tags:' ),
'edit_item' => __( 'Edit Design Tag' ), 
'update_item' => __( 'Update Design Tag' ),
'add_new_item' => __( 'Add New Design Tag' ),
'new_item_name' => __( 'New Design Tag Name' ),
'menu_name' => __( 'Design Tags' ),
  );    

  register_taxonomy('design_tag',array('design'), array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'designs' ),
  ));

  // Design Categories
  $labels = array(
'name' => _x( 'Design Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Design Category', 'taxonomy singular name' ),
'search_items' =>  __( 'Search Design Categories' ),
'all_items' => __( 'All Design Categories' ),
'parent_item' => __( 'Parent Design Category' ),
'parent_item_colon' => __( 'Parent Design Category:' ),
'edit_item' => __( 'Edit Design Category' ), 
'update_item' => __( 'Update Design Category' ),
'add_new_item' => __( 'Add New Design Category' ),
'new_item_name' => __( 'New Design Category Name' ),
'menu_name' => __( 'Design Categories' ),
  );    

  register_taxonomy('design_category',array('design'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'designs' ),
  ));  

// Create post type
$labels = array( 
    'name' => _x( 'Designs', 'design' ),
    'singular_name' => _x( 'Design', 'design' ),
    'add_new' => _x( 'Add New', 'design' ),
    'add_new_item' => _x( 'Add New Design', 'design' ),
    'edit_item' => _x( 'Edit Design', 'design' ),
    'new_item' => _x( 'New Design', 'design' ),
    'view_item' => _x( 'View Design', 'design' ),
    'search_items' => _x( 'Search Designs', 'design' ),
    'all_items' => __( 'All Designs', 'design' ),
    'not_found' => _x( 'No Designs found', 'design' ),
    'not_found_in_trash' => _x( 'No Designs found in Trash', 'design' ),
    'parent_item_colon' => _x( 'Parent Design:', 'design' ),
    'menu_name' => _x( 'Designs', 'design' ),
);

$args = array( 
    'labels' => $labels,
    'hierarchical' => false,

    'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'revisions' ),
    'taxonomies' => array( 'design_categories', 'design_tags' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 5,

    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => 'designs',
    'query_var' => true,
    'can_export' => true,
    'rewrite' => array( 
        'slug' => 'designs/%design_category%' ),
    'capability_type' => 'post'
);

register_post_type( 'design', $args );

}

add_filter('post_type_link', 'design_term_permalink', 1, 3);
function design_term_permalink($post_link, $id = 0, $leavename = FALSE )
{
   if ( strpos('%design_category%', $post_link) === 'FALSE' ) {
  return $post_link;
}
$post = get_post($id);
if ( !is_object($post) || $post->post_type != 'design' ) {
  return $post_link;
}
$terms = wp_get_object_terms($post->ID, 'design_category');
if ( !$terms ) {
  return str_replace('designs/%design_category%/', '', $post_link);
}
return str_replace('%design_category%', $terms[0]->slug, $post_link);}
share|improve this question
add comment

1 Answer

I answered a similar question but with the details of how to do it yourself:

adding categories to custom post type in permalink

share|improve this answer
    
It looks like the URL has been updated –  Ian Dunn Oct 30 '12 at 0:22
    
d'oh - updating now, sorry –  sanchothefat Dec 4 '12 at 10:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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