0

I'm trying to create clean url's for my custom post type, but I can't seem to figure out how to make this work.

First I followed the Wordpress codex using publicly_queryable and query_var in my public function register_post_type: http://codex.wordpress.org/Function_Reference/register_post_type

I also found this stackexchange topic, I've added the classes but I couldn't make it work: Clean URL permalink for custom post type

I'm using the following code to register my custom post type:

register_post_type('team' , array(
  'labels' => $labels,
  'public' => true,
  'has_archive' => false,
  'menu_position' => 5,
  'menu_icon' => get_stylesheet_directory_uri(). '/teamProfiles/team-icon.png',
  'supports' => array('title', 'editor', 'thumbnail'),
  'rewrite' => false
));

As mentioned above I've tried adding some values from the codex as below:

'rewrite' => array('slug' => 'team'),
'query_var' => 'team',
'publicly_queryable' => true

Maybe a note, I've build my custom post type in as a PHP class. Hope someone can help me out.

3
  • Inside you're register_post_type you have rewrite set to false, but you say you "added" the other code as well. It looks like you have rewrite written twice. If that's not it, you should post exactly the code you are using otherwise it's hard to tell where exactly you added the additional code to and if you removed the 'rewrite' => false May 25, 2015 at 3:59
  • Also go to => example.com/wp-admin/options-permalink.php and refresh/save permalink structure. After changing structure it probably didn't update. May 25, 2015 at 12:50
  • @Candid thanks for your reply. I didn't add the rewrite code twice. I've tried updating permalink structure and that did seem to work. Thanks for that suggestion! :)
    – ronnyrr
    May 26, 2015 at 7:07

1 Answer 1

0

Generate WP can help you generate a clean CPT. If this doesn't work, try the site to make sure you didn't miss anything.


// Register Custom Post Type
function custom_post_type() {

    $labels = array(
        'name'                  => _x( 'Teams', 'Post Type General Name', 'text_domain' ),
        'singular_name'         => _x( 'Team', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'             => __( 'Team', 'text_domain' ),
        'name_admin_bar'        => __( 'Team', 'text_domain' ),
        'parent_item_colon'     => __( 'Parent Team:', 'text_domain' ),
        'all_items'             => __( 'All Teams', 'text_domain' ),
        'add_new_item'          => __( 'Add New Team', 'text_domain' ),
        'add_new'               => __( 'Add New', 'text_domain' ),
        'new_item'              => __( 'New Team', 'text_domain' ),
        'edit_item'             => __( 'Edit Team', 'text_domain' ),
        'update_item'           => __( 'Update Team', 'text_domain' ),
        'view_item'             => __( 'View Team', 'text_domain' ),
        'search_items'          => __( 'Search Team', 'text_domain' ),
        'not_found'             => __( 'Not found', 'text_domain' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
        'items_list'            => __( 'Teams list', 'text_domain' ),
        'items_list_navigation' => __( 'Teams list navigation', 'text_domain' ),
        'filter_items_list'     => __( 'Filter teams list', 'text_domain' ),
    );
    $args = array(
        'label'                 => __( 'Team', 'text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'thumbnail', ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => true,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => get_stylesheet_directory_uri(). '/teamProfiles/team-icon.png',
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => false,       
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'team', $args );

}
add_action( 'init', 'custom_post_type', 0 

Your Answer

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

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