Sort multiple content types by publish date in dotcontent.pullPerPage

28 views
Skip to first unread message

Dave Hess

unread,
May 9, 2024, 2:46:11 PMMay 9
to dotCMS User Group
I have multiple content types, all of which have a Publish Date field, and I want to build a search the retrieves and sorts them using the publish date field (newly published items first). My problem is that I need to explicity list the sort parameters which ends up grouping the results by content type.

For example, my query reads:
#set($results = $dotcontent.pullPerPage(
"+(contentType:Article contentType:Video1 contentType:Quiz contentType:Audio)",
1, 10,
"Video1.publishDate desc, Article.publishDate desc, Quiz.publishDate desc, Audio.publishDate desc"
))

In this example, all the Video1 content items are listed first (ordererd correctly), then the Article items (ordererd correctly), then Quiz items, etc. I seem to be unable to use "publishDate desc" in the sort field like I can with modDate so I can sort everything by publish date regardless of content type.

Is there a way to do this?

Mark Pitely

unread,
May 9, 2024, 2:54:19 PMMay 9
to dot...@googlegroups.com
If you need finer control, you can always use the sort tool.


#set ($sorted=$sorter.sort($results,publishdate))
#foreach ($con in $sorted)
#end

Should work. Might have to get a little fancier. Let us know if it doesn't work. 

M

--
http://www.dotcms.com - Open Source headless/hybrid CMS
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/cd5dcd25-2127-465d-8aef-7e96894fa692n%40googlegroups.com.

Dave Hess

unread,
May 9, 2024, 3:48:21 PMMay 9
to dotCMS User Group
That's an option, but I'm concerned about performance once there's a large amount of content. I'd have to pull all the content and sort it and then roll my own pagination.

Is that the only option I have?

Mark Pitely

unread,
May 9, 2024, 5:52:26 PMMay 9
to dot...@googlegroups.com
Sneaking suspicion here. dotCMS is really good about pretending to be acknowledging your sort, but not doing it.
Make sure all of those PublishDates are marked as indexed in the structure definition. If even one wasn't, do a reindex of those structures in the maintenance tab.
It will happily let you type sort by, but will give you moddate or title instead if they aren't indexed.
If that was the case, you are fixed. If not, that could be tricky. How many items are we talking about across all the structures?
M

Reply all
Reply to author
Forward
0 new messages