Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-05-07 23:52:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,755
Website GitHub

Articles modified in the last month

Can I use <txp:article_custom> to list articles modifed in the last month? Or over a time range, in general? All the time-based tag attributes (month/time) seem to operate relative to the posted date.

The reason: articles have a numeric custom field called “Price”. But when an item is sold, the client changes the price field to ‘sold’. I want to show those products on the site for a month after they’re sold to show stock movement / drive scarcity [I realise it’s not perfect, as any article could be modified any number of times after its price field has been altered, but it’s good enough].

If there’s no way to do it, I’ll fall back on expiry and just tell the client they need to set the expiry to a month hence as well. But I was just trying to make it simpler so they only have to remember to do one thing, not two.


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

Offline

#2 2025-05-08 03:48:14

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,907
Website GitHub

Re: Articles modified in the last month

If there’s not a way, you could make a little plugin hooked onto article_save / article_publish to set the expiry field if the price field / sold field is set.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2025-05-08 09:12:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,755
Website GitHub

Re: Articles modified in the last month

Hey, that’s a neat idea. I like that. It also means that it’s only ever updated when the price changes from number -> sold. I might do that.

Thank you.


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

Offline

#4 2025-05-08 09:37:33

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

Re: Articles modified in the last month

Currently, only Posted and Expires can be filtered, but it’s just few lines to include other date fields. Meanwhile, why wouldn’t your client just ‘Set expiry to now’ instead of modifying the price field? Then you can query sold articles with

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

Offline

#5 2025-05-08 11:53:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,755
Website GitHub

Re: Articles modified in the last month

etc wrote #339680:

why wouldn’t your client just ‘Set expiry to now’ instead of modifying the price field?

That’s an option. Probably neater and preserves the price history. I like this, thank you.


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

Offline

#6 2025-05-08 14:51:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,755
Website GitHub

Re: Articles modified in the last month

etc wrote #339680:

<txp:article_custom expired time="-1 month" sort="Expires desc" />...

Hmm, this is also showing non-expired articles. I only want to see ones that have expiry set. Can I exclude the others somehow?

Trace shows:

SELECT {all the fields} FROM textpattern WHERE 1 AND `Posted` BETWEEN FROM_UNIXTIME(1744123654) AND FROM_UNIXTIME(1746715654) AND Section  IN ('products') AND Status IN (4) ORDER BY Expires desc LIMIT 0, 6

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

Offline

#7 2025-05-08 19:02:56

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

Re: Articles modified in the last month

Oops, sorry, will take a look. This one should work:

<txp:article_custom expired="now" time="-1 month" sort="Expires desc" />

Offline

#8 2025-05-08 19:45:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,755
Website GitHub

Re: Articles modified in the last month

etc wrote #339685:

<txp:article_custom expired="now" time="-1 month" sort="Expires desc" />...

Perfect. Note to self: read the docs properly regarding the bit that says “Boolean, or an English date string”.

Thank you.


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

Offline

Board footer

Powered by FluxBB