[wp-hackers] custom taxonomy list page?
Jeff Rose
jeff at jeffrose.ca
Sun Jan 30 17:57:44 UTC 2011
On Sat, Jan 29, 2011 at 10:35 PM,
<wp-hackers-request at lists.automattic.com>wrote:
>
>
> ---------- Forwarded message ----------
> From: Joshua Sibelman <joshua.sibelman at gmail.com>
> To: wp-hackers at lists.automattic.com
> Date: Sat, 29 Jan 2011 19:50:00 -0800
> Subject: [wp-hackers] custom taxonomy list page?
> I've been searching Google for this to no avail.
>
> I'm working on a restaurant site, and I have a custom post type for dishes,
> like so:
>
> function dish_register() {
> $labels = array(
> 'name'=>_x('Dishes', 'post type general name'),
> 'singular_name'=>_x('Dish', 'post type singular name'),
> 'add_new'=>_x('Add New', 'dish'),
> 'add_new_item'=>__('Add New Dish'),
> 'edit_item'=>__('Edit Dish'),
> 'new_item'=>__('New Dish'),
> 'view_item'=>__('View Dish'),
> 'search_items'=>__('Search Dishes'),
> 'not_found'=>__('No Dishes Found'),
> 'not_found_in_trash'=>__('No dishes found in Trash'),
> 'parent_item_colon'=>''
> );
>
> $args = array(
> 'labels'=> $labels,
> 'public'=> true,
> 'publicly_queryable'=>true,
> 'show_ui'=>true,
> 'show_in_nav_menus'=>true,
> 'query_var'=>'dish',
> 'rewrite'=>true,
> 'capability_type'=>'post',
> 'hierarchicial'=>false,
> 'menu_position'=>5,
> 'supports'=>array(
> 'title',
> 'editor',
> 'thumbnail',
> 'excerpt',
> 'custom-fields',
> 'revisions'
> )
> );
>
> register_post_type('dish', $args);
> }
>
> An example of one of the custom taxonomies I want to use is this:
>
> register_taxonomy('Main Ingredient', array('dish'), array(
> 'hierarchical' => true,
> 'label' => 'Main Ingredient',
> 'singular_label' => 'Main Ingredient',
> 'query_var'=>true,
> 'rewrite' => true)
> );
>
>
> The custom taxonomies are working fine in the admin, and I can go to
> http://myurl.com/main-ingredient/pork and see a list of all dishes with
> pork in them.
>
> What I'm wanting to do is be able to hit http://myurl.com/main-ingredientand get a list of all the various main-ingredient values.
>
> I found this reference, which is exactly what I'm trying to do:
>
> http://wordpress.stackexchange.com/questions/4663/custom-taxonomy-listing-page-when-no-term-set-all-terms
>
> But the solution is not working for me - I'm still getting a 404 when going
> to http://myurl.com/main-ingredient
>
> Any suggestions on how best to do this?
>
> Thanks,
> Josh
>
> WordPress should handle this automatically. I'm doing much the same thing
and I think this is the key:
'rewrite' => array(
'slug' => 'main-ingredient'
)
Add that to your taxonomy definition, visit the permalinks and re-save them.
This is working for me on a plugin I'm developing.
More information about the wp-hackers
mailing list