Allergen data contract

Allergens are a taxonomy. Items carry terms; terms carry a name, a description and an icon.

The taxonomy

allergen, registered for the content types selected in the allergen settings. A content type that is not selected has no allergen data.

Terms are the restaurant's own library, seeded with seventeen entries covering common declarable allergens and frequently requested intolerances.

Term fields

Field Storage
Name The term name
Description The term description
Icon Term meta key pom_category_thumbnail, holding a URL

An allergen with no stored icon falls back to a built-in icon only when its slug matches a built-in allergen. A custom allergen with no icon has none.

Reading an item's allergens

$allergens = wp_get_post_terms( $post_id, 'allergen', array( 'fields' => 'all' ) );

foreach ( $allergens as $allergen ) {
    $icon = get_term_meta( $allergen->term_id, 'pom_category_thumbnail', true );
}

Ordering

Allergen terms are ordered with the same stored position as menu categories, in the term meta key tax_position. The public filter renders them in that order.

Writing allergens

Allergens are assigned with the standard taxonomy functions. Match one behavior of the product: when a translation layer is active, an item's allergen assignment is applied to all of its translations, so allergen data cannot diverge between languages.

foreach ( pll_get_post_translations( $post_id ) as $translated_id ) {
    wp_set_post_terms( $translated_id, $allergen_ids, 'allergen' );
}

The public filter

Guests filter by selecting allergens to avoid. The mechanism is a query parameter and a cookie of the same name:

Name Purpose
a_la_carte_allergens Comma-separated allergen slugs, as a query parameter and as a 30-day cookie

When present on an archive request, the main query gains a tax_query excluding those terms:

array(
    'taxonomy' => 'allergen',
    'field'    => 'slug',
    'terms'    => $slugs,
    'operator' => 'NOT IN',
)

The filter therefore hides matching items rather than showing them.

A separate cookie, pom_rm_allergens_visibility, records whether a guest has chosen to display allergen icons. It is a display preference and does not affect the query.

Caching implications

Because the filter is expressed as a query parameter, a filtered archive is a distinct URL. A page cache in front of the site must not serve a filtered response to an unfiltered request, and must respect the parameter as part of the cache key.

Shortcode Output
[post_allergens] The allergen icons for an item
[allergens_list] The full library, with the visibility toggle and the information panel
[allergens_filter] The selectable filter form

See Front-end shortcodes.

Integration guidance

  • Never derive allergens from any other data. They are only ever what an editor assigned.
  • Never present a missing assignment as "no allergens" in a context that implies verification.
  • Preserve the exclusion semantics if you build an alternative filter: guests select what to avoid.
  • Keep assignments aligned across translations.