Get all children of a node at Controller level either published on unpublished
Currently i am using this method to get children of a node but it only returns the published or visible children, is there a method to get both the published and unpublished ones
Current code:
var allCount = Umbraco.Content(Guid.Parse("guidsample")).Children.ToList();
Umbraco has a Published Content cache that is super optimised for reading content on the front end of your website, as its name suggests it ONLY contains 'published' items!
The method you are using above is wired to work with the Published Content cache, which is why your unpublished items are missing.
So in terms of what to do... depends on what you are trying to do?
Essentially if you are working on the front end implementation of the site, then you probably shouldn't be trying to display or count unpublished items - if you need to show unpublished items on the front end efficiently in this way then publish them!! (you could add an embargo date or a checkbox to prevent content from being accessed... if that is the reason to have them unpublished but counted!)
Now if you are in the backoffice of Umbraco, in a custom editor or event, then you can use the ContentService...
this operates directly against the database layer, and so is slow, and should be avoided for the front end implementation, but you'll find a GetPagedChildren + CountChildren method that may be of use.
Finally if you are on the front end of the site, and need to query unpublished content - the other approach would be to use Examine, the search service that ships with Umbraco - the InternalIndex (usually used for the backoffice search) will contain both Unpublished and Published items, so in theory you could query this index to have a quicker way than the contentservice to locate unpublished item...https://our.umbraco.com/Documentation/Reference/Searching/Examine/
Get all children of a node at Controller level either published on unpublished
Currently i am using this method to get children of a node but it only returns the published or visible children, is there a method to get both the published and unpublished ones Current code:
Hi Rabea
Umbraco has a Published Content cache that is super optimised for reading content on the front end of your website, as its name suggests it ONLY contains 'published' items!
The method you are using above is wired to work with the Published Content cache, which is why your unpublished items are missing.
So in terms of what to do... depends on what you are trying to do?
Essentially if you are working on the front end implementation of the site, then you probably shouldn't be trying to display or count unpublished items - if you need to show unpublished items on the front end efficiently in this way then publish them!! (you could add an embargo date or a checkbox to prevent content from being accessed... if that is the reason to have them unpublished but counted!)
Now if you are in the backoffice of Umbraco, in a custom editor or event, then you can use the ContentService...
https://our.umbraco.com/apidocs/v8/csharp/api/Umbraco.Core.Services.Implement.ContentService.html
this operates directly against the database layer, and so is slow, and should be avoided for the front end implementation, but you'll find a GetPagedChildren + CountChildren method that may be of use.
Finally if you are on the front end of the site, and need to query unpublished content - the other approach would be to use Examine, the search service that ships with Umbraco - the InternalIndex (usually used for the backoffice search) will contain both Unpublished and Published items, so in theory you could query this index to have a quicker way than the contentservice to locate unpublished item...https://our.umbraco.com/Documentation/Reference/Searching/Examine/
if that helps!
regards
Marc
Thanks a lot Marc!
is working on a reply...