I can not sort by TV with getresource

Hi,

I have a couple of event and I print it from the newest to the oldest.
I use two TV: event_start, event_end and I defined the output as the following (US format)

GetResouce look like this

[[getResources? 
					&parents=`5`
					&idx=`1`
					&limit=`0`
					&includeContent=`1`
					&includeTVs=`1`
					&sortbyTVType=`{"event_start":"ASC"}`
					&tplWrapper=`@INLINE [[+output]]` 
					&tpl=`evenementsTpl`
					&showUnpublished=`0`
					&showHidden=`1`
				]]

Note:; I also tried with &sortbyTV={"event_start":"ASC"}

You can see here, the order is not correct Nos événements - Société de développement d'Arzier-Le Muids
I think the problem should be aroud sortbyTVType or sortbyTV, isn’t?
Did I use the bad sort?

Cheers

Try this instead:

&sortbyTV=`event_start`
&sortdirTV=`ASC`
&sortbyTVType=`datetime`
1 Like

Yes!!! Thanks. This works

I have an additional question
How can I use a where close?

I would like to show only the future events include today date

where datetime >= today

I tried to add the following in my getResource without success

where={"datetime:>=" => [[!+nowdate:default=now:strtotime:date=%Y-%m-%d]]}

Note: datetime print 2024-01-18

Then all event prior today should not be shown

You can either use the &tvFilters property

[[!getResources? 
	...
	&tvFilters=`event_start>=[[!+nowdate:default=`now`:date=`%Y-%m-%d`]]`
]]

or the &where property (for example) like this:

[[!getResources? 
	...
	&where=`["EXISTS (SELECT 1 FROM `modx_site_tmplvars` t INNER JOIN `modx_site_tmplvar_contentvalues` tc ON tc.tmplvarid = t.id WHERE CAST(tc.value AS DATETIME) >= CURDATE() AND t.name = 'event_start' AND tc.contentid = `modResource`.id)"]`
]]

If you already use the TV “event_start” for the sorting (as shown in my previous post), then this might also work:

[[!getResources? 
	...
	&where=`["CAST(IFNULL(tvSort.value, tvDefault.default_text) AS DATETIME) >= CURDATE()"]`
]]
1 Like

Wonderful, thanks halftrainedharry