[wp-trac] [WordPress Trac] #13490: Permalinks Issues for Custom Post Types with Parents
WordPress Trac
wp-trac at lists.automattic.com
Sat May 22 20:37:16 UTC 2010
#13490: Permalinks Issues for Custom Post Types with Parents
--------------------------+-------------------------------------------------
Reporter: mikeschinkel | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Unassigned
Component: Post Types | Version: 3.0
Severity: normal | Keywords: reporter-feedback
--------------------------+-------------------------------------------------
Comment(by mikeschinkel):
Replying to [comment:1 dd32]:
> If you set it to be hierarchical, then it should allow an unlimited path
length, the same as pages, the only catch being it must be /<rewrite
slug>/../../../../../ etc.
Thanks for the response. I wasn't having any issue with path length. Or
maybe I misunderstand a correlation?
> After registering a post type, you need to flush the rewrite rules in
order for the new rules to take effect, This is probably whats caught you,
you've set it up first without the hierarchical flag set, then changed it,
which has enabled the UI, but the rules are still only for non-
hierarchical.
I'm pretty sure that is not the issue. Here is my code (currently in the
theme and not in a plugin while I work to get it right after which I plan
to move to a plugin); note the flushing of rewrite rules on every page
load:
{{{
add_action('init', 'tyc_post_types');
function tyc_post_types() {
register_post_type('restaurant',
array(
'label' => __('Restaurants'),
'singular_label' => __('Restaurant'),
'public' => true,
'show_ui' => true,
'query_var' => 'restaurant',
'rewrite' => array('slug' =>
'restaurants'),
'hierarchical' => true,
'supports' => array(
'title',
'excerpts',
'thumbnail',
'custom-fields',
'editor',
),
)
);
register_post_type('restaurant-location',
array(
'label' => __('Locations'),
'singular_label' => __('Location'),
'public' => true,
'show_ui' => true,
'query_var' => 'restaurant-location',
'rewrite' => array('slug' => 'restaurant-
locations'),
'hierarchical' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'custom-fields',
),
)
);
register_post_type('restaurant-menu',
array(
'label' => __('Menus'),
'singular_label' => __('Menu'),
'public' => true,
'show_ui' => true,
'query_var' => 'restaurant-menu',
'rewrite' => array('slug' => 'restaurant-
menus'),
'hierarchical' => true,
'supports' => array(
'title',
),
)
);
global $wp_rewrite;
$wp_rewrite->flush_rules(false);
}
}}}
So I'm pretty sure it's not a case of setting without the hierarchical
flag set then changed it but having the rules still being non-
hierarchical. I'm guessing maybe you are making an assumption that it
works as expected but that it actually isn't working as expected? (Forgive
me if my guess is wrong and it's just me misunderstanding somehow.) Maybe
you could take my code above and test it?
> For the rest of restaurant-locations vs restaurants, I dont fully
understand, To me it sounds like you want to have the latter as child
"pages" of the location?
Having restaurants as children of locations? No, the other way around;
locations as children of restaurants.
> If so, thats fully supported -as the same post type-, If you want them
to be different post types, you need to handle the permalinks yourself,
through add_rewrite_rule(), as the post type URL rewriting only handles
the basic /slug/...../ permastructure, nothing fancy, But WordPress has
nothing stoping you from using something fancy, you just need to write the
rule yourself.
Okay, yes it is possible to come around and add more rewrite rules but
it's not possible (AFAICT) to assign a more complex rule using
`register_post_type()`so we end up with vestigial rules in the list, and a
long list of rules can be a performance drain for page load so I don't
want to have excess rewrite rules that are never used.
Also, there's another aspect of the ticket I don't think you picked up on
and that's the strong interest in having URLs that have the same slug,
i.e. "miami" is the location for all three restaurants in this case:
{{{
http://example.com/restaurants/johns-seafood/miami/
http://example.com/restaurants/marys-ale-house/miami/
http://example.com/restaurants/big-jims/miami/
}}}
Currently WordPress doesn't handle duplicate slugs and wants to make it
look like this which is sub-optimal for UX:
{{{
http://example.com/restaurants/johns-seafood/miami/
http://example.com/restaurants/marys-ale-house/miami-2/
http://example.com/restaurants/big-jims/miami-3/
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/13490#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list