[ad_1]
Hi,
I have a custom post type set up for a food menu. The restaurant has multiple locations, and each food item is not available at every location. Each item has its own post, and a custom taxonomy for dietary restrictions (ie. gluten free, vegetarian, vegetarian option available, etc.)
When I use the following code for the front end, it displays *all* possible taxonomy content instead of that which is specific to the post.
The problem begins under the <!– food dietary notice –> line.
<!-- food loop code begins -->
<?php
/* grab the location from the post slug, which matches the food_locations taxonomy */
$foodLocation = get_post_field( 'post_name', get_post() );
$foodStuff = array(
'tax_query' => array(
array(
'taxonomy' => 'food_locations',
'field' => 'slug',
/* drop the slug into the food_locations taxonomy term */
'terms' => $foodLocation,
),
),
/* reduce the taxonomy query to the food post type */
'post_type' => 'food',
'posts_per_page' => '99',
'orderby' => 'title',
'order' => 'ASC',
);
$displayFood = new WP_Query( $foodStuff );
while ( $displayFood->have_posts() ) : $displayFood->the_post();
?>
<div class="col-lg-4 pb-3 d-flex align-items-stretch">
<div class="card food-card">
<div class="card-body">
<!-- food product title -->
<h5 class="card-title"><?php the_title(); ?></h5>
<!-- food price -->
<p>$<?php echo the_field('food_price'); ?></p>
<!-- food dietary notice -->
<p><?php $terms = get_terms( 'dietary_type' );
if ( ! empty( $terms ) ){
echo '<ul class="venue-food-diet">';
foreach ( $terms as $term ) {
echo '<li>' . $term->name . '</li>';
}
echo '</ul>';
}
?></p>
<!-- food description -->
<p class="card-text"><?php echo get_the_content(); ?></p>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
<!-- food loop code ends -->Thanks,
James
The page I need help with: [log in to see the link]
