Skip Navigation

[Resolved] Display Product's Primary Category

This support ticket is created 4 years, 3 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.

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 4 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1811571

Tell us what you are trying to do? I am wanting to be able to show a products primary category assigned dynamically for a template page. For most of my template pages I am able to use Toolset's shortcodes to call custom fields or other parts of the post metadata.

I am wanting to get a Products Primary category to display on the page. Right now I can use the shortcode [wpv-post-taxonomy type="product_cat" format="name"], but this only works if one category is selected. If a product has mutliple categories the shortcode will display all categories.

I came across a topic discussing yoast_SEO primary filter, but I was unsure if this is what I could use or if it would work for my case.

https://toolset.com/forums/topic/using-main-category-as-filter-in-views/

#1812039
term-id-filter.JPG

Hello,

How do you setup the "products primary category"? If it is using "Yoast SEO" plugin, you can display the primary category ID with shortcode:
[wpv-post-field name="_yoast_wpseo_primary_product_cat"]

Pass above shortcode as attribute of below taxonomy view:
- Query Taxonomy Product categories
- Filter by:
Terms with ID set by the shortcode attribute
See screenshot term-id-filter.JPG

Display above taxonomy view's shortcode like this:
[wpv-view name="My amazing custom post list" term='[wpv-post-field name="_yoast_wpseo_primary_product_cat"]']