Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2026-05-07 16:38:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,591
Website GitHub

Date ranges including expired articles

I’m going round in circles here. The goal is to show a <txp:article_custom> list that satisfies:

  • section=“products”
  • Is Live
  • Is current (i.e. not expired)
  • May have expired within the last 7 days

In other words, show all for-sale products AND recently sold items (where expiry date is within 7 days before now). Anything that expired beyond 7 days ago should be excluded.

Presumably I need to set expired="1" to include all expired articles, then use month / time attributes to limit the exposure to -7 day. But I can’t get it to work for all conditions above. If I get the expired articles, I don’t get the current ones. And vice versa. Or I get them all, irrespective of publication/expiry date.

Alternatively, I thought maybe using an actual expiry time in expired that’s +7 days from time="now". But that just shows a rolling window of products.

Do I need to be more clever here and do some calculations to plug values into the various <txp:article_custom> attributes? Any clues gratefully appreciated.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#2 2026-05-07 22:26:18

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,321
Website GitHub

Re: Date ranges including expired articles

Have a look at these two threads. One or the other or both may help?


TXP Builders – finely-crafted code, design and txp

Offline

#3 2026-05-08 01:25:59

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,591
Website GitHub

Re: Date ranges including expired articles

Ah that first one might work, using time="since". I was using “now” and “posted” and various other values and not getting anywhere. Maybe combining that with expired="1" will consider both current and sold products.

I’ll try tomorrow. Thank you. I did search the forum and hit a few possible links, but didn’t turn that one up. Knew I’d seen an answer somewhere buried.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#4 2026-05-19 13:22:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,591
Website GitHub

Re: Date ranges including expired articles

Finally got round to circling back on this. Couldn’t get the since approach to work despite various fiddling. It just returned no results.

I’ll try and do some more forensic investigation and report back once I’ve tried some more. In the meantime if anybody has any pearls of wisdom, please shout.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#5 2026-05-20 07:58:53

etc
Developer
Registered: 2010-11-11
Posts: 5,713
Website GitHub

Re: Date ranges including expired articles

Let us put it the opposite way: what combination of expired, month and time attributes would be natural for

Posted <= NOW() AND (Expires IS NULL OR Expires > '1 week ago')

Currently, expired = "-1 week" time="since" should give Expires > '1 week ago', which excludes the articles with no expiry date.

Offline

#6 2026-05-20 22:14:59

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,591
Website GitHub

Re: Date ranges including expired articles

etc wrote #343271:

expired = "-1 week" time="since" should give Expires > '1 week ago', which excludes the articles with no expiry date.

Okay, thank you. That shows only articles that have expired in the last week, which is half the problem solved. So is it possible to list all non-expired articles in the section too? Essentially combine (all current live articles in section) + (those recently expired within the last week)?

I guess I could do it with two <txp:article_custom> tags – one for all live articles, and one for just recently expired – and concatenate a <txp:variable> up with the IDs from both calls in a 3rd <txp:article_custom id='<txp:variable name="wanted_article_ids" />' />. Bit resource intensive, though.

How about fields? Can that be leveraged in some way?

Last edited by Bloke (2026-05-20 22:18:47)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#7 2026-05-21 08:00:18

etc
Developer
Registered: 2010-11-11
Posts: 5,713
Website GitHub

Re: Date ranges including expired articles

I don’t know which natural attributes combination should mix both live and recently expired articles. We have three time-related attributes: expired, month and time. The combination expired + time is already used, but it outputs only expirable articles. In your case, if you set all unsold articles expiry date in some far future, it might work. But how to handle the general case, to tell txp ‘add live articles too’? I’m not sure this should be the default behaviour, sometimes you may want only expired articles. We could employ a valueless month here, but it looks a bit weird:

<txp:article_custom month expired = "-1 week" time="since" />

Ideas?

Offline

#8 2026-05-21 08:49:59

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,591
Website GitHub

Re: Date ranges including expired articles

Yeah, it’s not a natural request. So maybe it would be best if I duplicate the calls and build it manually.

I can’t think of a neat way to offer both current and expired content. At least I know it’s not just me being dense!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#9 2026-05-22 08:23:26

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,414
Website GitHub Mastodon Twitter

Re: Date ranges including expired articles

What if you create two variables?

<txp:variable name="expired"><txp:article_custom break="," month expired = "-1 week" time="since"><txp:article_id /></txp:article_custom></txp:variable>
<txp:variable name="live">....

<txp:article_custom id='<txp:variable name="expired" />,<txp:variable name="live" />'>
....

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#10 2026-05-22 08:29:17

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,591
Website GitHub

Re: Date ranges including expired articles

Yes, that’s what I meant, thanks. But it’s expensive using 3x article_custom calls so I was exploring ways to do it in fewer. Preferably one.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#11 2026-05-22 08:47:48

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,321
Website GitHub

Re: Date ranges including expired articles

If the articles can follow each other consecutively, you can get away with two article_custom tags after one another and no variables. And then there’s your very own smd_query and Oleg’s etc_query … for constructing a single query.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2026-05-22 08:57:56

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,321
Website GitHub

Re: Date ranges including expired articles

Actually, I just tried this version once again (with expired in the mix) and it worked on the demo site:

<txp:article time="since" month="-1month" expired />

Maybe it’s just txp:article and not txp:article_custom? On the demo site, I have a section “testing”, and if_section block with the above tag in the default template, with a new article, an article that expired in the last 30 days and an article that expired more than 30 days ago.

EDIT: hmm, on second thoughts maybe that’s published in the last 30 days and also expired. Not quite the same thing. Might that combination be workable for your situation?.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB