Skip Navigation

[Resolved] Display a list of woocommerce categories based on the current page title

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.

This topic contains 6 replies, has 2 voices.

Last updated by giuliaS 6 years, 4 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#303383

Hi,
I am trying to make a webstore with description Page for every brand. In this page I'd like to display a list of all the woocommerce products categories of the brand.

Because it seems to be impossible to estabilish a relation through a Type Custom Post and a Woocommerce Post or Taxonomy, I looking for an easy way to obtain a list of woocommerce category related (in any way) to the current page.

To do this I'm trying in this way:
1. The Brand Page is named "PIPPO"
2. I make a Woocommerce Category also named "PIPPO"
3. I make some woocommerce child Category for every product line of that brand.
4. I have to make a View that show all the Woocommerce Categories that are child of a category with the same name of the current post.

This (the point 4 of the list) seems not to be so easy. If I define a view with a query filter that shows only the categories child of a specific one, well... that works. But I can't find a way to define to show child categories of [wpv-post-title], instead of a specific title. How can I get this? Or maybe you have a better way to relate posts with woocommerce categories?

Thanks in advance for your answer.

#303686

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

I suggest you try create a nested view:
1) parent view list terms of tax woocommerce-categories
Filter with:
term name = current post title,
You will try Views filter hook "wpv_filter_taxonomy_query" to apply such a filter:
wpv_filter_taxonomy_query:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_taxonomy_query/

2) child view list terms of tax woocommerce-categories, filter with:
Select taxonomy terms whose parent is the value set by the parent view.

#303700

Ok, this is exactly what I need. But i still don't understand how to apply this filter term name= current post title. Should I write some PHP code? In what page? Maybe this is out of my skills.

#304074

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Since it is a custom PHP codes question, if you need more assistance for it, please try duplicate same problem in a test site, fill below private detail box with login details, also point out the problem page URL and problem view URL, I need test and debug it in a live website. thanks

#304500

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Thanks for the details, I can login into your website, and will feedback if there is any found

#304764

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Since your website isn't in English, and the FTP access isn't valid, I can not see any files when I login into your website with FTP access, it takes time to test and debug in your website, I have modified below in your website:
1) child view list terms of tax woocommerce-categories, filter with:
Select taxonomy terms whose parent is the value set by the parent view.
hidden link

2) parent view list terms of tax woocommerce-categories (Views ID is 106)
hidden link
Use above child view as a field.

3) add below codes in your theme/functions.php:

add_filter( 'wpv_filter_taxonomy_query', 'term_name_current_title_func', 10, 3 );
function term_name_current_title_func( $tax_query_settings, $view_settings, $view_id ) {
	if($view_id == 106){
		$title= get_the_title();
		$tax_query_settings['name__like'] = $title;
	}
	return $tax_query_settings;
}

4) create a test post with title "Master Chef Barbecue", and put the parent view into it.
hidden link

See the result:
hidden link

Please check if it is what you need.

#304766

This is EXACTLY what I need. Thanks a lot, you're awesome!