Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Use txp:related_articles to find partial matches
Is this possible?
Say I have a bunch of product articles with a bunch of custom fields like:
- brand
- colour
- sku
- size
- …
If someone picks a product, I want to show other products from that section (product type) that match the brand, in other colours/sizes. But if I use match="brand, colour, size"
it only finds other products in that section that exactly match those custom fields.
If I relax it and choose just match="brand"
then it does indeed find other colours and sizes but also finds articles with the same colour and size as the main article. I don’t want that.
So the first question is: can I exclude articles that already match the CFs in the current article? Or do I need to use a huge limit
and manually check each article in the returned set to see if it matches, and skip it if it does. Then stop when I reach, say 6 successful articles that have different CFs to the main one.
Secondly, or alternatively, I have the sku
custom field and that is fairly well structured. All products of the same family tend to have the same initial sku, with variants on the end:
- BA12345B
- BA12345/C
- BA12345-R
- BA12345PRC
- …
So it occurred to me that I could maybe match on the first part of the sku to return products in the same range. The issue is there’s no real consistency between skus of different families, because they’re from different vendors/brands. So I’m not sure how to know how many characters to match against. Maybe the first 6 or so is enough.
It would be nice if there was some ‘family’ CF or data that I could assign to a category in each article, as that would make matching easier. But this data has come from an external spreadsheet and that info isn’t available.
Is there any way anyone can think of to do partial matching of values like that?
Or any other ways to achieve ‘other products in this range in different sizes/colours’? Maybe I’ll need to use article_custom with include/exclude to grab them instead, but I can’t think of a way to tell that to partial match either. Would match="brand, colour, size" exclude="colour, size"
do what I want? The firat part of the sku is a stronger signal that the product is from the same range.
Last edited by Bloke (2025-04-22 23:07:54)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Use txp:related_articles to find partial matches
I would try match="brand" exclude="colour, size"
, indeed, unless you don’t require both of them be different from the current set.
Offline