Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

How to get page in cq5 on the basis of their creation date

Avatar

Level 2

Hi,

 I have a requirement to get a list of 3 most recent page crated in cq5 so that i can  create their list .

Plz help me to understand how to achieve this. I need to work on this on urgent basis. plz help me.

how would be the sample query.

Thanks,

Amit

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi there Amit,
You can sort the entries by their property: "jcr:created".
The query for this (you can e.g. check in the debugger) would be:

 

path=/content/mysite/ type=cq:Page orderby=@jcr:content/jcr:created orderby.sort=desc

Or if you want it in java code:

 

Map map = new HashMap(); map.put("path", "/content/mysite"); map.put("type", "cq:Page"); map.put("orderby", "@jcr:content/jcr:created"); map.put("orderby.sort", "desc"); Query query = builder.createQuery(PredicateGroup.create(map), session); SearchResult result = query.getResult();

Hope that will help you
/Johan

View solution in original post

1 Reply

Avatar

Correct answer by
Level 7

Hi there Amit,
You can sort the entries by their property: "jcr:created".
The query for this (you can e.g. check in the debugger) would be:

 

path=/content/mysite/ type=cq:Page orderby=@jcr:content/jcr:created orderby.sort=desc

Or if you want it in java code:

 

Map map = new HashMap(); map.put("path", "/content/mysite"); map.put("type", "cq:Page"); map.put("orderby", "@jcr:content/jcr:created"); map.put("orderby.sort", "desc"); Query query = builder.createQuery(PredicateGroup.create(map), session); SearchResult result = query.getResult();

Hope that will help you
/Johan