Yummy Docs

Taxonomies

This plugin includes custom taxonomies for the recipes. The taxonomies work like the categories and tags for blog posts. You can also register your own taxonomies, and they will work just like the built-in custom taxonomies!

Included taxonomies #

You can edit taxonomy terms by clicking Recipes → Taxonomy Name at the WordPress dashboard, for example Recipes → Courses.

In addition the plugin adds two custom fields for terms.

Adding a custom taxonomy #

In addition to built-in taxonomies, you can also add your own taxonomies. Here's a code snippet demonstrating how to register a new taxonomy.

function my_custom_register_taxonomy() {

$labels = array(
'name' => __( 'Tests', 'recipes' ),
'singular_name' => __( 'Test', 'recipes' ),
'menu_name' => __( 'Tests', 'recipes' ),
'edit_item' => __( 'Edit Test', 'recipes' ),
'search_items' => __( 'Search Tests', 'recipes' ),
'not_found' => __( 'No test found', 'recipes' ),
'add_new_item' => __( 'Add New Test', 'recipes' ),
);

$args = array(
'label' => __( 'Test', 'recipes' ),
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'query_var' => 'test',
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'test',
'with_front' => false,
),
);

register_taxonomy( 'my_test', 'yummy_recipe', $args );
}
add_action( 'init', 'my_custom_register_taxonomy' );

Important! As always it is recommended to insert custom functions with a site specific plugin or with a plugin like Code Snippets. If you insert custom function directly into your theme files, they may be overridden on theme updates!

For more information please see the WordPress documentation about taxonomies.

After you have successfully inserted the code, the taxonomy should be visible at Recipes → Taxonomy Name. Now you should go to Settings → Permalinks, and click Save Changes. You don't have to change the anything, just save the settings. This clears the permalink structure of the site, and makes sure that the new taxonomy works correctly.

Now when you have registered the taxonomy, you can use it just like the built-in taxonomies. You can for example add it to the filters shown on the Recipe Search block.

Of course you must first have recipes using the new taxonomy, otherwise it won't be shown for example on the recipe search filters.