Understanding Permalinks on Custom Post Types

I hate to try to reinvent the wheel here, but none of the suggested post seem to work in answering my question. I am building a system for our 30 Under 30 honorees, which is basically setup as a portfolio of images. The types of post I am creating will be called “honorees”, and the overall menu called “30 Under 30”. The portfolio page that they are all displayed on, will be http://domain.com/30under30/ But for some reason the posts are created as http://domain.com/honoree/%honoree-name%/

How do I change the my taxonomy follow menu name, as opposed to post type name? The labels section of my code from functions.php is below

Read More
   function project_custom_init()  
{  
  $labels = array(  
    'name' => _x('Honorees', 'post type general name'),  
    'singular_name' => _x('Honoree', 'post type singular name'),  
    'add_new' => _x('Add New', 'honoree'),  
    'add_new_item' => __('Add New Honoree'),  
    'edit_item' => __('Edit Honoree'),  
    'new_item' => __('New Honoree'),  
    'view_item' => __('View Honoree'),  
    'search_items' => __('Search Honorees'),  
    'not_found' =>  __('No honorees found'),  
    'not_found_in_trash' => __('No honorees found in Trash'),  
    'parent_item_colon' => '',  
    'menu_name' => '30 Under 30'  
  );  
 $args = array(  
    'labels' => $labels,  
    'public' => true,  
    'publicly_queryable' => true,  
    'show_ui' => true,  
    'show_in_menu' => true,  
    'query_var' => true,  
    'rewrite' => true,  
    'capability_type' => 'post',  
    'has_archive' => true,  
    'hierarchical' => false,  
    'menu_position' => null,  
    'supports' => array('title','editor','author','thumbnail','excerpt','comments')  
  );  
  // The following is the main step where we register the post.  
  register_post_type('honoree',$args);  
  // Initialize New Taxonomy Labels  
  $labels = array(  
    'name' => _x( 'Tags', 'taxonomy general name' ),  
    'singular_name' => _x( 'Tag', 'taxonomy singular name' ),  
    'search_items' =>  __( 'Search Types' ),  
    'all_items' => __( 'All Tags' ),  
    'parent_item' => __( 'Parent Tag' ),  
    'parent_item_colon' => __( 'Parent Tag:' ),  
    'edit_item' => __( 'Edit Tags' ),  
    'update_item' => __( 'Update Tag' ),  
    'add_new_item' => __( 'Add New Tag' ),  
    'new_item_name' => __( 'New Tag Name' ),  
  );  
    // Custom taxonomy for Honoree Tags  
    register_taxonomy('tagportfolio',array('honoree'), array(  
    'hierarchical' => true,  
    'labels' => $labels,  
    'show_ui' => true,  
    'query_var' => true,  
    'rewrite' => array( 'slug' => 'tag-portfolio' ),  
  ));  

Any help would be appreciated. I’m trying my best to understand the code as I figure this out.

Related posts

Leave a Reply

2 comments

  1. Your post_type slug will default to the name of the post_type unless specified otherwise. So, in it’s most basic form you can set a custom base slug as follows,

    'rewrite' => array( 'slug' => 'slug-name-here');

    Currently, you have it set to true only.

    Don’t forget to visit your permalinks page in the dashboard to flush your rewrite rules after you make your changes to get the new base rule to work!

    Also take a look at,

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

    Which contains a great deal of information about the parameters associated with custom post types, including the initial rewrite rule. You can do some advanced things to meet numerous scenarios with rewrite rules, but for the most basic of requirements you can rely on the above suggested snippet.

    I’d provide more examples, but I’m writing from a phone…

    Good luck!

  2. You cannot have a custom post type page with the permalink format you want. This format is reserved for Pages (I mean WP native “Page” post type).

    UPDATE : This answer is wrong, see comments for details.

    The better way to achieve the result you want is to create a page named 30Under30, which will have the http://domain.com/30under30/ permalink, and then create a custom page template that will display the custom post type list.

    In the honoree.php file, put the following code (comments with “Template Name” keyword is not optional):

    <?php /* Template Name: Honoree */
        query_posts(array('post_type' => 'honoree'));
    
        // loop to display honoree posts
        while(have_posts()): the_post();
    
        endwhile;
    ?>
    

    Then select it in the “Page Template” menu of your 30Under30 page.