Home Forums ACF PRO Displaying items grouped by "custom post type categories"


Displaying items grouped by "custom post type categories"

  • I have a custom post type called Item Category that simply contains the names of all my item categories (saved as posts) such as

    • Vehicles
    • Rental
    • Camping

    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

    • Item: Car
    • Item: Truck

    Category: Rental

    • Item: Car
    • Item: Tent

    Category: Camping

    • Item: Tent

    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?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.