Forum list » Templates »
Children.Query() and retain dates
Pages:  1
(62 posts)

Children.Query() and retain dates

When building the sub-navigation structure, we typically use:

....selectedArticle.Children.Query() ...


But the output also contains nodes with expired retain dates.

It seems to work with WAFContext.Session.Query(), but in this case we'd like to use the Children.Query().

Is there an easy way to exclude retained nodes when using Children.Query(-)?

(6 posts)

You can choose to retrieve only published contents:

var items = s.Children.Query<HierarchicalContent>().Where(AqlHierarchicalContent.ShowInMenu == true | AqlHierarchicalContent.IsPublished == true).Execute();
(62 posts)

Ok, that would work. Thanks.

But I expected IsPublished=true to be default from Webnodes ;)

(144 posts)


You shouldn't have to check IsPublished in a query to only return the published nodes. By default, all queries in Webnodes returns only published nodes.

There are some common things that might be confusing. First of all, if you are logged into edit in the samme session, the visit session will return unpublished and deactivated nodes. Opening a new tab or browser window might not be enough to create a new session. Your best bet is to open a different browser and test if you get the same result. If you still have issues contact us, and we can take a look at the site/code in question!


(31 posts)

Thanks for the tip Vidar :)

I have tested this a bit and thought I should share the results. As you said, the result does differ if you are logged into Edit at the same time. I also thought that there was a bug here because I'm always in edit when I test these things. I doubt that this will be a problem for customers since visitors don't have access to edit anyway. If you for some reason want to have the same result regardless of whether or not a user is logged into edit, you can use one of the following queries.


1) This will return only published/activated content, but because we are using SystemSession it will ignore read access and show content that the user doesn't have access to (like member-only content).



2) This will return the same as the query above, except for content the user doesn't have access to.

.Where(AqlHierarchicalContent.IsPublished == true
& AqlHierarchicalContent.ShowInMenu == true
& AqlHierarchicalContent.ReleaseDate < currentDate
& (AqlHierarchicalContent.RetainDate < new DateTime(1900,01,01) | AqlHierarchicalContent.RetainDate > currentDate))


As mentiond earlier, it shouldn't be necessary to do this extra work.