Problem with related products - by Peter

This topic has 10 replies, 3 voices, and was last updated 6 hours, 44 minutes ago ago by Andrew Mitchell

  • Avatar: Peter
    Peter
    Participant
    March 18, 2026 at 11:30

    Hi,
    I’m having trouble with related products. It’s showing products from other categories in my categories. I check if the products are assigned correctly, and even though the product doesn’t belong to the “thermometers” category, it still appears in that category.

    Content is visible for topic creator and
    support staff only.
    9 Answers
    Avatar: Ayan Rahman
    Ayan Rahman
    Support staff
    March 18, 2026 at 11:43

    Hi,

    Thank you for reaching out to us.

    Could you please test if the same issue occurs when using a default theme, such as Storefront? (Appearance — Themes).
    If the behavior continues regardless of the theme being used, it suggests that the problem may not be related to the theme itself. In this case, we would recommend you contact support of woocommerce plugin – https://wordpress.org/support/plugin/woocommerce/

    Warm Regards,
    The 8Theme Team

    Avatar: Peter
    Peter
    Participant
    March 19, 2026 at 08:25

    Hello

    I have an issue with the Related Products section on single product pages.

    I am trying to filter related products by the current product’s primary category (set in Yoast SEO). I have overridden the template file by copying:

    wp-content/themes/xstore/woocommerce/single-product/related.php

    to my child theme:

    wp-content/themes/xstore-child/woocommerce/single-product/related.php

    In this file, I build a custom $related array containing only product IDs from the correct category. I have verified via debug output that the $related variable contains the correct product IDs before being passed to $args[‘post__in’].

    However, the etheme_slider() function seems to ignore the post__in argument and displays random products from the entire store instead.

    My questions:
    1. Does etheme_slider() use the post__in parameter from $args, or does it build its own WP_Query internally?
    2. If it builds its own query, is there a filter or parameter we can use to control which products are displayed?
    3. Is there an official recommended way to filter related products by category in XStore?

    Thank you in advance for your help.

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    March 19, 2026 at 10:27

    Hello, Peter,

    In fact, the function etheme_slider fully utilizes all the parameters passed through the $slider_args attribute, and the function itself does not contain any additional filters.

    Best regards,
    8Theme Team

    Avatar: Peter
    Peter
    Participant
    March 19, 2026 at 10:52

    Thank you for your reply.

    I have done further debugging and I found a contradiction that I need your help with.

    In the related.php template, I build a custom $related array with correct product IDs filtered by category. I have verified via debug output that:
    1. $related contains the correct product IDs
    2. $args[‘post__in’] is set to these correct IDs
    3. Even after apply_filters(‘woocommerce_related_products_args’), I force $args[‘post__in’] = $related

    However, etheme_slider() still displays completely different, random products — not the ones in $args[‘post__in’].

    Could you please clarify:
    1. Does etheme_slider() use $args[‘post__in’] to limit which products are shown, or does it ignore it and run its own query?
    2. If etheme_slider() runs its own internal query, what parameter should we use to pass our custom list of product IDs?
    3. Could you share a code example of how to correctly limit related products to a specific list of IDs when using etheme_slider()?

    Thank you!

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    March 19, 2026 at 13:39

    In this case, we kindly ask you to provide us with FTP access so that we can check this.

    Best regards,
    8Theme Team

    Avatar: Peter
    Peter
    Participant
    March 19, 2026 at 13:49

    ok

    Content is visible for topic creator and
    support staff only.
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    March 19, 2026 at 14:04

    Thank you for providing access. As far as we can see, the request is functioning correctly and accepts all values from $args[‘post__in’]. The issue appears to be related only to the values you are passing to this parameter. We also noticed that the parameter ‘orderby’ => ‘rand’ is used, which means that the products with the specified IDs will be selected randomly.

    Please review the attached video.

    Best regards,
    8Theme Team

    Files is visible for topic creator and
    support staff only.
    Avatar: Peter
    Peter
    Participant
    March 19, 2026 at 14:24

    Hello,

    Thank you so much for your help! The video you attached was very helpful and pointed us in the right direction.

    It turned out that the issue was not with etheme_slider() at all — as you correctly pointed out, it works perfectly. The problem was in the product IDs we were passing to post__in.

    The root cause was that our products have a parent category (Medical Devices) and multiple subcategories (Inhalers, Thermometers, etc.). The code was picking the parent category instead of the correct subcategory, which resulted in random products being displayed.

    We fixed it by filtering out parent categories and using only the subcategories to query related products. Everything is working correctly now.

    Thank you again for your support!

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    March 19, 2026 at 17:01

    Thank you for your message and for sharing the details of your solution. We are glad to hear that the video was helpful and that you were able to identify and resolve the issue successfully.

    It’s great to know that everything is now working correctly after adjusting the query to use only subcategories. We appreciate your feedback and the time you took to update us on the outcome.

    If you have any further questions or need additional assistance, please don’t hesitate to contact us.

    Best Regards,
    8Theme’s Team

  • Viewing 10 results - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.