Skip Navigation

[Resolved] Creating related products within the same post type

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 8.97 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by David 2 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#2301195

I have created a single custom post type called "Products" with a handful of custom fields. I would like the ability to define related products for each product but I'm not sure how best to go about doing that. It seems the Post Relationship mechanism is meant for connecting two different post types but I'm trying to create a link or links within a single post type. I'm confused on how to do this and must be overlooking something simple. This would be like how WooCommerce products can relate to other WooCommerce products – they're all the same post type.

Hope that makes sense.

#2301423

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for getting in touch.

You can actually do this by bringing the WOocommerce product post type under our Types control and modifying the post type settings.

To do this you will first need to disable your WOocommerce plugin then go to Toolset -> Post Types and recreate the product post type by using the Plural as Products, singular as Product and the slug as product.

Once you've done this scroll to "Section to display when editing" and enable Page Attribute and then scroll to options and enable hierarchical.

Finally just re-enable your Woocommerce plugin and you should now be able to set a parent product for the product you've created using the Page attribute option.

Please let me know if this helps.

Thanks,
Shane

#2301427

Shane-

This is not a WooCommerce site. We're not selling products on this site, it's more of a marketing site. I've created my own CPT called "Products". I was just using WooCommerce as an example and how you can define related products.

So I currently have 118 products entered into my CPT. I want to easily define "Related Products" for each product as needed so that I can link to those products on the product detail page. Hope that makes better sense. This isn't a relationship between two different post types.

#2301449

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

I've created my own CPT called "Products". I was just using WooCommerce as an example and how you can define related products.

Thank you for the clarity. In such a case the instructions will be the same with the exception of creating the product.

You should still be able to edit the Post Type and check the options as i've described in my previous post.

Edit your post type and scroll to "Section to display when editing" and enable Page Attribute and then scroll to options and enable hierarchical.

Thanks,
Shane

#2302207
Upsells and Cross-sells.jpg

Shane-

I understand what you're saying but this is not what I need. I don't need to define a parent for a product. I'm already using taxonomy to categorize these paint products (Primers, Activators, Hardeners, Basecoats, etc.).

Let's say I have three primers (White, Grey, and Black). On the product detail page for the White Primer, I want to show a section of "related products" which could show the Grey and Black primers because they're in the same category but I may also want to define other related products from other categories.

Another example would be if you were on the product detail page of a Hardener product and wanted to show related Activator products.

I'm attaching a screenshot of how WooCommerce handles Upsells and Cross-sells. I would say this is the type of functionality I'm looking for – the ability to define any number of products. Hope that makes sense.

#2302393

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for the clarity.

In this case you will either need to do it using Custom Fields or Taxonomies as you have. Then on the product details page you use a view to display products that are attached to the same Taxonomy/Custom field that the page that you're viewing has.

So you can set the filter to display posts that Taxonomy A selected and Custom Field value B.

Please let me know if this sounds a bit more of what you want to achieve.

Thanks,
Shane

#2303981
Product Detail page.jpg

Shane-

So yes, I created a View that is filtered by the taxonomy of the page it's shown on so that all of the other products in the same category are listed in a table at the bottom of the product detail page (see attached).

However, in the cases where I may want to assign one or more products from other categories as Related or Associated products, would you suggest I use a repeater field for those product ID's so that I can ultimately target and query their fields for display? Hope that makes sense. Moreover, not sure if there's an easy way to have a single field (not repeating) that has a comma separated list of ID's that I would then somehow parse and run through a loop to display their information. If that's doable and you have a code suggestion for parsing that list, that would be great.

Thank you for your help!

#2304913

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Yes the repeater field would work as you're able to filter your view by a list of post ids.

Essentially if you have the repeater field with the ID you can add each ID to the field. When outputting the field it can be done as a comma separated list and this would allow you to pass you ids into the view filter for the POST ID as a shortcode attribute.

This is what your view shortcode will look like.

[wpv-view name='my-view' ids="[types field='repeater-field' separator=',' ]"]

Thanks,
Shane

#2305243

Thank you Shane. I've got some additional finessing to do but was able to use a repeater field to define related and alternate products successfully. Now I just need to import in all those product relationships. Appreciate your help.