[pdoResources] Create virtual subsection from tv date

Hi,

Until now, I had this resources tree as content of a container :

2022

  • resource 1
  • resource 2

2021

  • resource 3
  • resource 4

2020

  • resource 5

2019

  • resource 6
  • resource 7
  • resource 8

The front end result is this :

Each resource of this tree has a TV with a specific date.
I can manipulate it with a strtotime output filter if need.

For several reasons, I want to avoid to use the first level with the year.
In other world, I want a resources tree inside my container like this :

  • resource 1
  • resource 2
  • resource 3
  • resource 4
  • resource 5
  • resource 6
  • resource 7
  • resource 8

But I want to get the same front end result see before !
I think is possible to use the TV date to filter the year and get the “children” from this year, but I don’t know how !

Am I right ? Is it possible to do this without intermediate year’s containers ?
And if yes, how to doing this with pdoResources ?

You can either use the &where property

[[!pdoResources?
    ...
    &includeTVs=`myDateTV`
    &showLog=`1`
    &where=`["YEAR(myDateTV) = 2022"]`
]]

or maybe the &tvFilters property.

[[!pdoResources?
    ...
    &includeTVs=`myDateTV`
    &tvFilters=`myDateTV>=2022-01-01 00:00:00,myDateTV<<2023-01-01 00:00:00`
]]

Than @halftrainedharry for your help.
However have to detail my purpose : I want a pdoResources call which doesn’t need update each year.
My customer should be able to upload new resource with correct filled TV’s date and get this new resource on the right place.
Next year, in 2023, the new resource with the 2023’s year on the TV date should “create” the new year “parent” on the front-end.
I don’t know if I’m clear :slight_smile:

You could move your pdoResources call into a custom snippet.

In your snippet execute pdoResources with $modx->runSnippet(...) and use the property &return=`json` to get the data back as JSON.

Then loop through the items, extract the year from the TV field, and if the year is different than the one in the previous item, output a new subsection before outputting the item.

Hmmm, sounds a bit complicated to me…
I thought there would be an easier solution…

But thank you @halftrainedharry :slight_smile: