getResources: How to get items in the future from today

Summary

My goal is to use getResources to display the next three items on the website from today’s date. I would like to use the published-on timestamp for this. Only one parent is used as the source.

Step to reproduce

My current source code looks like this:

[[getResources?
&parents=22
&tpl=aktuellesTpl
&showHidden=1
&limit=3
&includeTVs=1
&where={"publishedon:>=":"[[!currentDateTime?]]"}
&sortbyTV=publishedon
$sortdirTV=ASC
&debug=true
]]

currentDateTime returns the current datetime:
return date(‘Y-m-d H:i:s’);

That’s the SQL out of my log file:

SELECT modResource.id, modResource.type, modResource.pagetitle, modResource.longtitle, modResource.description, modResource.alias, modResource.link_attributes, modResource.published, modResource.pub_date, modResource.unpub_date, modResource.parent, modResource.isfolder, modResource.introtext, modResource.richtext, modResource.template, modResource.menuindex, modResource.searchable, modResource.cacheable, modResource.createdby, modResource.createdon, modResource.editedby, modResource.editedon, modResource.deleted, modResource.deletedon, modResource.deletedby, modResource.publishedon, modResource.publishedby, modResource.menutitle, modResource.content_dispo, modResource.hidemenu, modResource.class_key, modResource.context_key, modResource.content_type, modResource.uri, modResource.uri_override, modResource.hide_children_in_tree, modResource.show_in_tree, modResource.properties, modResource.alias_visible FROM modx_site_content AS modResource WHERE ( modResource.parent IN (22,23,24,67,69,70,73,74,75,80,81,82,83,84,85,86,87,88,89,91,92,93,94,95,96,97,98,99) AND modResource.deleted = 0 AND modResource.published = 1 ) ORDER BY publishedon ASC LIMIT 3

Observed behavior

My source code is working so far, but it returns me 3 items, which are always the latest based on the published-on timestamp. It does not show me the next 3 items from today’s date.

Expected behavior

I expect, that from today the next 3 items shall appear.

Environment

MODX version 3.1.0-pl

Try changing the sorting direction to DESC instead.

Also “publishedon” is a resource field and not a TV. So you probably should use &sortdir and &sortby.

Thank you.

I tried, but unfortunately it didn’t changed the behavior.

Any other ideas?

The resource field “publishedon” stores a timestamp (and not a string as a date TV does). So you probably have to return a timestamp in your snippet to make it work.

Also, as you use an uncached snippet call to create the &where property, call the getResources snippet uncached as well:

[[!getResources?
    ...
    &limit=`3`
    &where=`{"publishedon:>=":"[[!currentDateTime]]"}`
    &sortby=`publishedon`
    &sortdir=`ASC`
]]

Snippet currentDateTime:

<?php
return time();

I tried it the way you suggested, but still facing with the same issue.
Its the second day I spent on this request without getting it done.

Let me describe my issue:
Lets say I have 5 items in the future:

  1. 2025-04-30 09:00:00
  2. 2025-05-05 11:00:00
  3. 2025-10-17 08:00:00
  4. 2025-11-09 08:00:00
  5. 2025-11-30 01:00:00

The goal is to display 3 → 2 → 1. The time doesn’t matter, because there is max. one entry per day.

But it only shows me 5 → 4 → 3.

Thanks halftrainedharry,

that was the solution. I only forgot to change the

&sortdir

back to ‘ASC’.

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