How to get page in cq5 on the basis of their creation date | Community
Skip to main content
New Participant
October 16, 2015
Solved

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

  • October 16, 2015
  • 1 reply
  • 1681 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ojjis

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

1 reply

Ojjis
OjjisAccepted solution
New Participant
October 16, 2015

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