1

I added a custom taxonomy (separate categories for a custom post type) like this:

register_taxonomy(self::$slug . '_category', array(self::$slug), array(
    'label' => 'Kategorien',
    'labels' => array(
        'name' => 'Kategorien',
        'singular_name' => 'Kategorie',
        'all_items' => 'Alle Kategorien',
        'edit_item' => 'Kategorie bearbeiten',
        'view_item' => 'Kategorie anzeigen',
        'update_item' => 'Kategorie aktualisieren',
        'add_new_item' => 'Neue Kategorie erstellen'
    ),
    'hierarchical' => true,
    'rewrite' => array(
        'slug' => 'referenzen-kategorie'
    )
));

On the homepage I am fetching the categories like this:

$categories = get_categories(array(
    'type' => 'sb_reference',
    'taxonomy' => 'sb_reference_category'
));

And displaying it. Now comes the catch: The admin of the site wants to influence the order of the displayed categories and his desired order is neither alphabetical nor by post count, but by his perceived relevance of the categories. So basically I have to give the taxonomy an additional field that he can write the order of the categories in (i.e. CategoryA is 0, CategoryB is 2, CategoryC is 1 etc.)

My question: How can I add an additional field to the custom taxonomy or what are my alternatives?

1

Thanks to this great tutorial, I just found the answer myself.

Wordpress offers the action hooks sb_reference_category_add_form_fields, sb_reference_category_edit_form_fields, create_sb_reference_category and edited_sb_reference_category (these are named after the custom taxonomy, in my case sb_reference_category). With these hooks, it is easy as pie to add and save a custom field to the taxonomy.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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