pdoResources not sorting by TV correctly

Using the following pdoResources call:

{'!pdoResources' | snippet : [
	'parents' => $parent,
	'depth' => 99,
	'includeTVs' => 'year,month,image,image_alt,image_desc',
	'processTVs' => 1,
	'prepareTVs' => 1,
	'useWeblinkUrl' => 1,
	'limit' => $limit,
	'sortby' => '{"year":"DESC", "month":"ASC"}',
]}	

the output I’m getting is:
YEAR 2023, MONTH 10
YEAR 2023, MONTH 12
YEAR 2023, MONTH 7

Any suggestions? TV month is a listbox.

Seems like it only parses it as a number, if the TV type is set to Number, but doesn’t try to cast it when it’s a listbox.

Changing the sortby parameter to:

'{"year":"DESC", "FIELD(month, 1,2,3,4,5,6,7,8,9,10,11,12)":"ASC"}'}

worked like a charm! :slight_smile:

All TV values are stored as strings. (Because all TVs use the same database column.)
So it looks to me, like the data is sorted as a string and not as a number.

There exists some code in pdoResources to cast the value to the correct type before sorting.

Either change the “Input Type” of your TV to “Number”.
Or use the properties sortbyTV, sortdirTV and sortbyTVType for the sorting.

1 Like

Makes sense. Looks like those properies aren’t documented here or here. Is there any aditional documentation on this?

They are mentioned in the documentation for getResources.
As pdoResources was a replacement for getResources, most of the getResources functionality was implemented as well.

The problem with sortbyTV in this case at hand is, that it only allows the sorting by one TV. You can’t sort this way by multiple TVs.

1 Like

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”.