[wp-hackers] [wp-testers] custom post type permalinks

Mike Schinkel mikeschinkel at newclarity.net
Tue May 18 17:29:46 UTC 2010


Hi Frank,

Is this not what you need?

	register_taxonomy('phone_cat', 
		array('iphone','android','blackberry'), 	// <--- Multiple post types here
		array(
			'hierarchical'    => true,
			'label'           => array('name' => _x( 'Phone Cats', 'taxonomy general name' )),
			'query_var'       => 'phone-cat',
			'rewrite'         => array('slug' => 'phone-cats' ),
		)
	);

-Mike

On May 18, 2010, at 5:44 AM, Frank Bueltge wrote:

> I had build a another test with the custom post types. The goal is 3
> post_types with the same categories, like a CMS function.
> 
> my source:
> 
> add_filter( 'pre_get_posts', 'fb_get_posts' );
> function fb_get_posts( $query ) {
>    if ( is_home() || is_front_page() )
>        $query->set( 'post_type', array( 'post', 'iphone' ) );
> 
>    return $query;
> }
> 
> add_action( 'init', 'fb_create_post_types', 0 );
> function fb_create_post_types() {
> 
>    $labels = array(
>        'name' => _x( 'iPhones', 'post type general name' ),
>        'singular_name' => _x( 'iPhone', 'post type singular name' ),
>        'add_new' => _x( 'Add New', 'iphone' ),
>        'add_new_item' => __( 'Add New iPhone' ),
>        'edit' => _x( 'Edit', 'iphone' ),
>        'edit_item' => __( 'Edit iPhone' ),
>        'new_item' => __( 'New iPhone' ),
>        'view' => __( 'View iPhone' ),
>        'view_item' => __( 'View iPhones' ),
>        'search_items' => __( 'Search iPhones' ),
>        'not_found' => __( 'No iPhones found' ),
>        'not_found_in_trash' => __( 'No iPhones found in Trash' ),
>        'parent' => __( 'Parent iPhone' )
>    );
> 
>    $args = array(
>        'labels' => $labels,
>        'public' => true,
>        'publicly_queryable' => true,
>        'show_ui' => true,
>        '_builtin' => false,
>        'capability_type' => 'post',
>        'hierarchical' => false,
>        'rewrite' => array('slug' => 'iphone', 'with_front' => true ), //
> Permalink
>        'query_var' => true, // 'iphone', // for WP_Query Schema
>        'taxonomies' => array('category'),
>        'menu_position' => 5,
>        'supports' => array( 'title', 'editor', 'author', 'excerpt',
> 'trackbacks', 'custom-fields', 'comments', 'revisions', 'thumbnail',
> 'page-attributes' ),
>        'show_in_nav_menus' => true,
>        'menu_icon' => get_stylesheet_directory_uri() .
> '/postnavimages/iphone.png',
>    );
>    register_post_type( 'iphone', $args);
> }
> 
> so it is possible to use all categories in all post_types, on my example
> only one - iphone :), only a test
> 
> works fine without active permalinks and not with active permalinks. It is
> not possible to vie the single-post. Also dosnt work the archive.
> 
> Please - is this a bug or a an error on my source.
> Thanks for reply and time.
> 
> Best regards
> Frank
> 
> 
> 
> On Mon, May 17, 2010 at 4:20 PM, Frank Bueltge <frank at bueltge.de> wrote:
> 
>> I have also this problem. It works fine without active permalinks, but not
>> with active permalinks.
>> 
>> simple test-source:
>> function post_type_movies() {
>>    register_post_type(
>>        'movies',
>>        array(
>>            'label' => __('Movies'),
>>            'public' => true,
>>            'show_ui' => true,
>>            'rewrite' => array('slug' => 'movies'), // Permalink
>>            'query_var' => 'movies' // for WP_Query Schema
>>        )
>>    );
>>    register_taxonomy( 'actor', 'movies', array( 'hierarchical' => true,
>> 'label' => __('Actor') ) );
>>    register_taxonomy( 'production', 'movies',
>>        array(
>>            'hierarchical' => false,
>>            'label' => __('Production'),
>>            'query_var' => 'production',
>>            'rewrite' => array('slug' => 'production' )
>>        )
>>    );
>> }
>> add_action('init', 'post_type_movies');
>> 
>> Works fine without Permalinks.
>> Thanks for reply
>> 
>> 
>> On Mon, May 17, 2010 at 3:20 PM, Greg M Boone <boone.greg at gmail.com>wrote:
>> 
>>> Greetings,
>>> I've been reading almost everything I can find on creating custom post
>>> types, and wondering how to configure a custom post type so that it will
>>> match the same permalink structure specified in the wordpress settings. In
>>> the functions.php for
>>> 'rewrite' => true, generates: /post_type/post-title structure
>>> 'rewrite' => false, generates: /?podcast=post-title
>>> using array ('slug'...) would just generate a custom slug before the post
>>> title, and array ('with_front') doesn't seem to do anything since I don't
>>> have a prefixed structure.
>>> 
>>> My custom structure specified is /%year%/%postname%/ does anyone know how
>>> to get a custom post type to follow this rule?
>>> --
>>> Greg
>>> 
>>> _______________________________________________
>>> wp-testers mailing list
>>> wp-testers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-testers
>>> 
>> 
>> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list