Hi,
I’m really confused right now. I’ve been trying to display my custom posts but cannot make it to be grouped by their custom category(taxonomy). I have managed to display them by category but the category is hard-coded. These is what I got at the moment.
<?php
$args = array(
'post_type' => 'foods',
'tax_query' => array(
array(
'taxonomy' => 'food_categories',
'field' => 'slug',
'terms' => 'bread'
)
)
);
$foods = new WP_Query($args);
if($foods->have_posts()) {
while($foods->have_posts()) {
$foods->the_post();
?>
<h1><?php the_title(); ?></h1>
<div>
<?php the_content(); ?>
</div>
<?php
}
}
else {
echo 'no foods';
}
?>
How can I display all my custom post grouped by their respective “Category” by not hard coding the “category name”?