Custom Related products Looper instead of Pre-made element

Hi Guys,

I am aware you have a pre-made “related products” element, which works well, but for those of us who want to make a more customized feeling product layout that follows the rest of the websites design (without having to resort to just css modifications of an element).

Is there a way to make a custom loop for a related products element. I already have made one which runs on the home page for pre-set taxonomies of a product.

But here is the breakdown of what I would like to try and do if it is possible with custom attrributes as well:

1. On the single product page where the related products will be, can we define a way for the same product to not show itself in the related products data i.e. { if > title matches > then > do not show product} ?

2. Can we also specify some terms within for the related product details such as brand (if available), and taxonomies x, y, z, and then if further possible allowing for set levels of priority and sorting such as -
Brand = Priority 1
Taxonomy X = Priority 2
Taxonomy Y = Priority 3
Taxonomy Z = Priority 4
Sort by > Priority Descending or Ascending

Screenshot as below for reference:

Hi Dracostar,

Thanks for reaching out.
You can achieve this by using the Query String option of Looper Provider. I would like to refer to my colleague Kory’s comment in the following thread, which may be helpful to you to create the Query String on Featured image and Prakash comment in the other thread on Related product.

Hope it helps.

Hi tristup,

Thanks for the link, I am still very new to WP_Query. But I was able to somewhat reverse engineer and understand the way the data is output.

However I don’t think I have implemented it right.

I applied the query but it seems to show the same data regardless, and isn’t finding more relevant information based off the products category (as I specified in the code), while also using the “title” for reference.

For example:
If a product is has the title: " Ceramic Ball Bearing 18x12x4mm, Teflon Shields"

It still shows only the same repeating content in the “related products” below. I have a feeling I didn’t enter in the code correctly (please see below).

And thanks again for any assistance you can give~


Hello @Dracostar,

To get the query string that you need, you can add this code to your child theme’s functions.php file temporarily:

$tax_query[] = array(
   'post_type' => 'post',
   'tax_query' => array(
       'relation' => 'AND',
           'taxonomy' => 'pwb-brand',
           'field'    => 'name',
   		'terms'    => 'relevance',
   		'operator' => 'IN',
           'taxonomy' => 'product_cat',
           'field'    => 'name',
   		'terms'    => 'relevance',
   		'operator' => 'IN',

$query = array(
   'post_type'           => 'product',
   'post_status'         => 'publish',
   'ignore_sticky_posts' => 1,
   'posts_per_page'      => 8,
   'orderby'             => 'title',
   'order'               => 'desc',
   'tax_query'           => $tax_query

var_dump( http_build_query( $query ) );

And you should be getting something like this:


Hope this helps.

Hi Reunel,

Thank you kindly for the assistance I was able to generate the string like you had sent me before (see below).

However it seems to only return the same product it is currently on in the “related products section”. Now either that means the string I generated is faulting somewhere, or it is looking too specifically for an exact match in title.

Here is the string I generated for reference (I beleive the string you made as well returns the same results)


Thankyou again for your assistance wherever you can help :slight_smile:

Hello @Dracostar,

We can refer to this thread for the simple related products query string:


Old Thread:

Hi Ruenel! Thankyou so much for that I think that mostly gets majority of the functionality we are after. Short of it being more dynamic and adding some other customizable if statements.

Its a good solution, and I don’t know why I didnt think of using this from that post beforehand, apologies for that, but thankyou for the assistance from you and your colleagues.

I do hope this will be a pre-made filter in the theme later on down the track as I can see the appeal for those wanting a more custom built “related” or upsell/cross sell section :smiley:

Thank you once again.

Hello @Dracostar,

Glad that we were able to help you. Please feel free to reach us if you have any queries regarding our theme and theme settings.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.