Skip to content
Custom fields for WordPress that are quick to build and quick to load. Get Pro

Project

A restaurant menu

Dishes by course, with price, photo and allergens, from a content type.

3 minutes Works with the free plugin

What you build. A menu with dishes, sorted by course (Starters, Mains, Desserts), each with a price, a photo, allergens and a vegan badge. Editors add dishes like posts. The page of the menu prints them by course.

What you use. A content type, a taxonomy, one field group, ugly_find().

Step 1. The content type

  1. UglyFields → Content types → New content type.
  2. Choose A list of things.
  3. Change the example: singular Dish, plural Dishes, key dish.
  4. In Parts of the editing screen, keep Title and Featured image, and turn off Content editor. The fields will be all there is.
  5. In Addresses on the site, set Start of the address to menu.
  6. Create.
The New content type form filled in for Dish
The New content type form filled in for Dish.

Step 2. The taxonomy

  1. Open the Taxonomies tab, then New taxonomy.
  2. Choose Categories.
  3. Singular Course, plural Courses, key course. Under Content types, tick Dish.
  4. Create.

Make three courses from the new Courses screen of the Dishes menu: Starters, Mains, Desserts.

Step 3. The fields

  1. UglyFields → Field groups → New group. Name it Dish details.
  2. Add:
    • Number Price, with Smallest number 0, Step 0.5 and Text before the box €.
    • Checkboxes Allergens, with choices typed one per line: gluten, dairy, nuts, eggs.
    • Yes / No Vegan.
    • Text area Description.
  3. Location → Post type is Dish.
  4. Create group.
The builder with the fields of Dish details
The builder with the fields of Dish details.

Now add a dish: Dishes → Add new. The fields are there.

Step 4. The template of one dish

single-dish.php:

PHP
<?php get_header(); ?>

<?php while ( have_posts() ) : the_post(); ?>
	<article class="dish">
		<?php the_post_thumbnail( 'large' ); ?>

		<h1><?php the_title(); ?></h1>

		<p class="dish__price">€ <?php ugly_show( 'price' ); ?></p>

		<?php if ( ugly_get( 'vegan' ) ) : ?>
			<span class="badge">Vegan</span>
		<?php endif; ?>

		<?php if ( ugly_get( 'description' ) ) : ?>
			<p><?php ugly_show( 'description' ); ?></p>
		<?php endif; ?>

		<?php $allergens = (array) ugly_get( 'allergens' ); ?>
		<?php if ( $allergens ) : ?>
			<p>Contains: <?php echo esc_html( implode( ', ', $allergens ) ); ?></p>
		<?php endif; ?>
	</article>
<?php endwhile; ?>

<?php get_footer(); ?>

Step 5. The menu page, by course

page-menu.php:

PHP
<?php get_header(); ?>

<h1>Menu</h1>

<?php
$courses = get_terms( array( 'taxonomy' => 'course', 'hide_empty' => true ) );

foreach ( $courses as $course ) :
	$dishes = new WP_Query(
		array(
			'post_type'      => 'dish',
			'posts_per_page' => -1,
			'orderby'        => 'title',
			'order'          => 'ASC',
			'tax_query'      => array(
				array(
					'taxonomy' => 'course',
					'terms'    => $course->term_id,
				),
			),
		)
	);
	?>
	<section>
		<h2><?php echo esc_html( $course->name ); ?></h2>

		<?php while ( $dishes->have_posts() ) : $dishes->the_post(); ?>
			<article>
				<h3><?php the_title(); ?> <span>€ <?php ugly_show( 'price' ); ?></span></h3>
			</article>
		<?php endwhile; wp_reset_postdata(); ?>
	</section>
<?php endforeach; ?>

<?php get_footer(); ?>

Step 6. Only the vegan dishes

PHP
$vegan = ugly_find( 'dish', array( 'vegan' => true ), array( 'order' => 'price asc' ) );

What you learned

  • A content type, a taxonomy and a group are three separate things that work together by location.
  • ugly_find() gives you a WP_Query and takes conditions on fields as an array. For a taxonomy, use a normal WP_Query.
  • Everything you made is in ugly-json/, ready to commit.