Wednesday, 15 June 2011

php - How to put the category on the permalink of a custom post type -



php - How to put the category on the permalink of a custom post type -

i'm creating custom post types sharing categories of blog. , want set category name on permalink , delete custom post type name.

now have: www.mywebsite.com/custom-post-type-name/post-name

and want is: www.mywebsite.com/category/post-name

i tried set on register_post_type array 'rewrite' => array('slug' => '%category%') doesn't works. result www.mywebsite.com/%category%/post-name

thank in advance! (and sorry english)

$labels = array( 'name' => _x('whitepaper', 'post type general name'), 'singular_name' => _x('whitepaper', 'post type singular name'), 'add_new' => _x('add new', 'whitepaper'), 'add_new_item' => __('add new whitepaper'), 'edit_item' => __('edit whitepaper'), 'new_item' => __('new whitepaper'), 'all_items' => __('all whitepapers'), 'view_item' => __('view whitepaper'), 'search_items' => __('search whitepapers'), 'not_found' => __('no whitepapers found'), 'not_found_in_trash' => __('no whitepapers found in trash'), 'parent_item_colon' => '', 'menu_name' => 'whitepapers' ); $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' => true, 'menu_position' => null, 'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields'), 'taxonomies' => array('category'), 'rewrite' => array('slug' => '%category%') ); register_post_type('whitepaper',$args);

i don't think can create through rewrite argument, that's more complex , need endpoint mask api.

what endpoints?

using endpoints allows create rewrite rules grab normal wordpress urls, little @ end. example, utilize endpoint match post urls followed “gallery” , display of images used in post, e.g. example.com/my-fantastic-post/gallery/.

a simple case relatively easy accomplish own custom rewrite rules. however, powerfulness of endpoints shines more complex situations. if wanted recognise urls posts , pages ending “gallery”? if wanted able grab multiple different archive urls, e.g. day, month, year , category archives, “xml” appended in order output xml representation of archive? these situations endpoints useful allow add together string end of multiple rewrite structures single function call.

source : make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/

a tutorial custom post type permalinks includes using endpoint :

[part 2] http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2

approach on category :

https://core.trac.wordpress.org/ticket/19275

php wordpress custom-post-type permalinks

No comments:

Post a Comment