Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to search for only pages which are published using querybuilder?

Avatar

Level 9

We are trying to get json from components of specific pages to render on client.  We can individually lookup each required page by its template type:

 

path=/content/mysite/en/
type=cq:page
1_property=jcr:content/cq:template
1_property.value=/conf/mysite/settings/wcm/templates/my-page-template
some othe properties to narrow down the required page.

 

Then we can do another query to retrieve all its children, and iterate through them looking for the 2 components we required, and then copying each property to a model for later conversion to json.

 

The problem is that the first query returns unpublished pages, which the user should not yet be able to see.

How do we only return published content?

 

The page only seems to have 3 properties:

1) jcr:created

2) jcr:createdBy 

3) jcr:primaryType.

 

There is no property to give the published status?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @TB3dock 

 

You are running this query on your author instance where you have both published and unpublished pages. But your query is going to run on publish at the end of the day and no unpublished pages will be available on publish instance. So user will not be able to see any unpublished pages as part of the search result.

 

You can still use the below 2 property to query but it becomes redundant on publish instance.

2_property=@jcr:content/cq:lastReplicationAction
2_property.value=Activate

 

Thanks!

View solution in original post

3 Replies

Avatar

Community Advisor

Hi,

 

When a page is activated we will have below properties and can be added in query to retrieve only published pages

 

2_property=@jcr:content/cq:lastReplicationAction
2_property.value=Activate

 

For unpublished pages the cq:lastReplicationAction property wont be present in jcr:content node and for deactivated pages it will have value as Deactivate.

 

Hope this helps !

Avatar

Correct answer by
Community Advisor

Hi @TB3dock 

 

You are running this query on your author instance where you have both published and unpublished pages. But your query is going to run on publish at the end of the day and no unpublished pages will be available on publish instance. So user will not be able to see any unpublished pages as part of the search result.

 

You can still use the below 2 property to query but it becomes redundant on publish instance.

2_property=@jcr:content/cq:lastReplicationAction
2_property.value=Activate

 

Thanks!