Home › Forums › General Issues › Get posts based on relationship
Hi, I have to create a WordPress site in which I need to register tire products. Each tire product need to be categorized by:
1. Product Type – for Cars, Cargo, etc.
2. Brand – Michelin, Continental etc. Also each brand will have its own categories. Exmampe Michelin will have categories like Michelin-Cat-1, Michelin-Cat-2 etc.
3. Season – Summer, Winter and All seasons
When user click on “Tyres All” page, that page needs to show first Product Types. Tyres All page will redirect us in first “Product Type” post page. Each product type post will have a content with image, example in Car product type page. In that page we need to show all the seasons based on tire products that have been registered (get all seasons from tire products where product type is Car). On season click example in Summer we need to show all brands based on registered products (get all brands from registered tire products where product type is car and season summer). On brand click example Michelin, new page will be shown with brand categories based registered products (get all brand categories from tire products where product type is car, season is summer and brand is Michelin). On brand category click need to show products from that criteria.
I have created 4 custom posts for that:
1. Tires (products)
2. Product types
3. Brands
4. Seasons
I am using ACF Relationship and I have created 3 relationship fields for custom post type products to create a relation with other post types. Tires custom post type has following relationship fields:
1. Brands – from custom post type brands
2. Seasons – from custom post type seasons
3. Product Types – from custom post type product types
My problem is when we are in the Product type page (example product type – Car) how to get all the seasons based on product registerd with product type Car.
Is there any other solution instead of ACF Relationship to do that ?
Seems to me that you only need one custom post type — Tires (products). Then for this post type, create a custom field group that includes select fields for ‘Product Type’, ‘Season’, and ‘Brand’. Then you can just include some post filtering in your template files for the archive page (which is effectively a complete product list in this scenario).
@kaitlyn thank you for your response but “Product Type” need to have its own page. It will have text and image. In that page I need to show all the seasons from products where product type is selected. I can’t do product type, brand and season as select fields. I am using also FacetWP.
I hear you, but Product Type, Season, and Brand are all attributes whereby you filter a product. So you can create a page for Product Type by creating a template that pulls all of the possible values for a given attribute and generating a div for each. When you click through to one of the Product Types, you display a page of Product posts that is filtered by that Product Type. Then you can have, say, a sidebar that displays all the other attributes you can filter by (like Seasons). Something like the way Amazon presents its products. You have to visualize this as a relational database and imagine the data structures and their hierarchies.
@kaitlyn’s response is a good one. Tires should be the only post type. Brand, Season and Type should all be custom taxonomies associated with the tire post type. This will allow you to have pages associated with each of the taxonomies. For example, a list of all “Winter” tires, or a list of all “Good Year” tires or a list of all “Radial” tires, etc… Using custom taxonomies for these “attributes” you could even construct a custom search filter that could allow visitors to filter their selection by more than one of them, for example “Good Year Winter” Tires.
The topic ‘Get posts based on relationship’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.