I have a custom post type called Item Category that simply contains the names of all my item categories (saved as posts) such as
There are no ACF-related fields within this custom post type.
I have another custom post type called Items. Here I can create items and for each individual item, I can select multiple item categories (Vehicles, Rentals, Camping) based on the ACF “Relationship” field that pulls the categories from the Item Category CPT.
On the frontend of the website, I am wanting to display the items grouped by categories, something like this:
Category: Vehicles
Category: Rental
Category: Camping
When I run a query like this:
foreach ($posts as $key => $val):
echo $val->post_title; // Displays item name
print_r(get_field('category', $val->ID)); // Displays array of categories
}
, it simply displays items and it’s related categories.
How do I resolve this?