Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hello, this is more of a 'is it possible' type question. Keep in mind, I am no php master by any means, but can generally figure things out : )

Say i have a wordpress site that is for displaying menu items, focusing on pizza. I have a custom post type of 'menu items' and i would need several custom taxonomies attached to that post type. Things like toppings, sauces, cheeses, crusts, etc…

BUT, what if the end user doesn't want to name their taxonomies that way, say they wanted specialty toppings, veggies, meats, gluten free, instead?

Is there a way for me to name my custom taxonomies something general like, ingredient set 1, ingredient set 2, ingredient set 3, ingredient set 4, ect...and in the theme options panel, set up some sort of override for that taxonomy name? Something like:

Taxonomy Name: Ingredient set 1 -> Friendly Name: Toppings
Taxonomy Name: Ingredient set 2 -> Friendly Name: Sauces

etc…

I have tried searching online but haven't found anything about it, but my wording could be off.

Any ideas would be greatly appreciated!

share|improve this question
add comment

1 Answer

Yes, that's certainly possible, but you wouldn't override anything- instead you'd fetch and add the custom names when they're registered. For a quick example, say you have an option that stores the names:

$taxonomies = array(
    'ingredient_1' => 'Toppings',
    'ingredient_2' => 'Sauce'
);
add_option( 'my_tax_names', $taxonomies );

Then when you register the taxonomies:

$taxonomies = get_option( 'my_tax_names' );

foreach( $taxonomies as $key => $name ){
    register_taxonomy( $key, 'post', array( 'label' => $name ) );
}
share|improve this answer
    
I am working on a theme that I plan to sell and would like NOT to force the end user into my preset naming conventions. I'd like the theme to be as flexible as possible. So with your solution, I could add that snippet to the functions.php file, and in my theme documentation, state that they add the custom taxonomy names BEFORE applying the theme? Or is that asking too much of the end user? Or... Would it be possible to hold off the registration of the taxonomies until the end user checks a checkbox in the theme options panel, grabs their custom names, and drop them in the $taxonomies array? –  dvieira Jan 18 '13 at 18:02
    
taxonomies are registered on every request, so if the option is not yet set they won't exist until the user creates them. they would be free to create (or remove) them at any point after the theme is activated. this is a very basic example, you'll probably also want to expand this to accommodate more than a simple name, like provide the ability to set them to hierarchical or non-hierarchical, slug, etc.. take a look in the plugins repository at post type/taxonomy creation plugins for examples of how other developers handle the UI and code for this sort of thing. –  Milo Jan 18 '13 at 19:06
    
Will do Milo...thank you for your time :) –  dvieira Jan 18 '13 at 20:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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