Looking for clarification of the answer given by the very helpful halftrainedharry in Jan 2021 to the same question. The syntax in his answer doesn’t work for me. I am guessing it is a syntax problem:
Using runSnippet to call getResources after this line:
TV values of type “date” are all stored in the same format in the database.
I guess for the query you have to use this universal format and not your custom one.
It’s a bit of a hack. [[!+nowdate]] is technically a placeholder that doesn’t exist, so the default value of the output modifier will be used, which gets you the current datetime (that you then can format with date).
Did you change event_start to the actual name of your TV?
Can you maybe post the whole getResources snippet call you use?
I thought about writing a script from scratch, and it seems simple to eliminate the past event resources, but then I have no clue how to order the array of resources in chronological order:
OK I see the confusion. There are two ways to achieve the filtering.
The way you posted is when you create a custom snippet with PHP code, that then calls getResources (with $modx->runSnippet('getResources')).
Here you can’t use other MODX tags (like [[!+nowdate:default=`now`:date=`%Y-%m-%d`]] ) in the PHP code.
The other way is to call the snippet getResources directly in your page content or chunk (without creating a custom snippet).
Here nested MODX tags (like [[!+nowdate:default=`now`:date=`%Y-%m-%d`]] or [[!getDate]]) can be used.
I wouldn’t try to reinvent the wheel.
It’s quite a common use case to filter resources by a TV of type date, and getResources/pdoResources can both be used for this.
Want to thank you for all the help. At the moment nothing is working, and it is probably a good thing I live on the ground floor. Will need to take a break to save what little is left of my sanity.
It turns out that the crucial problem was what you initially mentioned: the format of the date in the nowdate snippet that is called by the getResources call:
And nowdate is just what it was in January of 2021:
return date('Y-m-d H:i:s');
The getResources call works if the nowdate snippet just uses Y-m-d but it does NOT work with d-m-Y, which is what I was using as the output format for the eventdate template variable.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.