Skip Navigation

[Resolved] Need help to display individual product from each subcategory in View Loop

This thread is resolved. Here is a description of the problem and solution.

Problem:
Need help to display individual product from each subcategory in View Loop

Solution:
You will require to use the Toolset View's filter hook "wpv_filter_query" in order to modify the view's query on fly.

You can find the proposed solution in this case with the following reply:

https://toolset.com/forums/topic/need-help-to-display-individual-product-from-each-subcategory-in-view-loop/#post-1787747

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by manishB-2 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1784379
toolset-view-functionality-diagram.jpg

Hi Support team,
I need a help to make a View display target results.

I want to display individual products from each subcategory in a toolset view loop based on the current Product primary category. So Main idea is "I have two Primary Product Categories and each category has more than 5 Subcategories and all products attached to subcategories and not to primary categories. So we can also consider that somewhere indirectly these products are connected with the Primary category too. So In my Single Product page, I have added "similar products View" that displays 5 to 6 Products in the same primary category in which current product is displayed. But the condition is, I want to display similar products only one Product from each subcategory." For better understanding. Please check the video below and also a screenshot of a diagram, that will show you what I am talking about.

hidden link

#1785703

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I review the video you shared and I understand that you want to display only one product belongs to your each sub-category.

if you can share problem URL and access details, Once I review your current setup, I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1787747

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

i've created the following views:
=> hidden link
- This is the taxonomy view to query the taxonomy product_cat

=> hidden link
- This is the product view to display only one product belongs to specific child term

Within the "Similar Products" section of your elementor template:
=> hidden link
I've added the view "tax-view-single-product-similar".

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

add_filter( 'wpv_filter_taxonomy_query', 'func_filter_by_parent_tax_term', 999, 4 );
function func_filter_by_parent_tax_term($tax_query_settings, $view_settings, $view_id) {
  global $post;
  
    if($view_id == 6683){
           
      $terms = wp_get_object_terms( $post->ID,'product_cat');
     
       foreach($terms as $k=>$v):
      		$parent = $v->parent;
      $child_terms = get_terms( 'product_cat', array( 'parent' => $parent, 'orderby' => 'slug', 'hide_empty' => true,'exclude'=>array($v->term_id),'fields'=>'ids' ) );   
      
      endforeach;

      $tax_query_settings['include'] =$child_terms;
      }
    return $tax_query_settings;
}

I can see its working as expected. Can you please confirm and let me know your feedback.

#1788093

Hi, I am sorry to bother you again Minesh,
But there was a misunderstanding of mine. My boss actually had asked a different query rule and displaying the similar products.

And correct Process to display the similar products is that, each subcategory has a list of Products Custom ids which are saved in a custom field called "product-id" and What my boss wants is

I have displayed the Excel file that includes the product IDs connected with Each Category. So Basically we want to first add a query filter which will be the "Current Category of the page where view is displayed" and after that, I need to check all connected Product IDs with the current Category and once the system finds available Product IDs then it will pull only 1 Product from each product ID And display them as similar products, For example, there are 12 Product IDs for that category then 12 Products will be displayed as Similar Products. I have explained all these details in the video. So please watch it and please, please help me to make it work. Its really important feature.

hidden link

All Credentials for access are still the same. you can access the site.

#1788399

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is totally new requirement. I'll split the ticket with your latest requirement as the solution I shared may help other users.

We will continue with your new requirement with the following ticket:
=> https://toolset.com/forums/topic/split-need-help-to-display-individual-product-from-each-subcategory-in-view-loop-get-product-id-from-term-custom-fields/

Feel free to close this ticket.

#1790145

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please feel free to mark resolve this ticket as well 🙂

#1790147

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.