help - 'Unpublished' items not being listed?

Topics: Troubleshooting, Writing modules
Dec 1, 2014 at 11:48 PM
Hi All, I'd really appreciate some help - I'm trying to create my first Orchard Website [I have only just started programming] and have used the following module for a carousel:

http://gallery.orchardproject.net/List/Modules/Orchard.Module.Tekno.FlexSlider

...the problem is, as others have reviewed - the Unpublish / Publish feature doesnt work for items; as in, if you unpublish an item - it simply disappears. I imagine it does actually set an 'unpublished flag', but the code for listing all your items appears to exclude 'unpublished items' so you cant return such an item to published in the future.

Can anyone point me in the right direction as to how to include 'unpublished' items in the listing and amend this oversight?
        public ActionResult Items(string groupName) {
            var list = Shape.List();
            //Sort By GroupName then SlideOrder
            var featuredItemsQuery = _contentManager.Query<FeaturedItemPart, FeaturedItemPartRecord>().OrderBy(fi => fi.GroupName).OrderBy(fi => fi.SlideOrder);

            if (!string.IsNullOrWhiteSpace(groupName)) {
                featuredItemsQuery.Where(fi => fi.GroupName == groupName);
            }
            var featuredItems = featuredItemsQuery.List();
            list.AddRange(featuredItems.Select(fi => _contentManager.BuildDisplay(fi, "SummaryAdmin")));

            dynamic viewModel = Shape.ViewModel();
            viewModel.ContentItems(list);
            viewModel.NumberOfItems(featuredItems.Count());
            
            return View(viewModel);
        }
Sorry if this is a no brainer, but i'm struggling with Orchard in general. Thanks for your time.
Dec 3, 2014 at 8:21 PM
Right now the query is defaulting to showing published only, as you have noticed. You just need to set the VersionOptions as so:
var featuredItemsQuery = _contentManager.Query<FeaturedItemPart, FeaturedItemPartRecord>(VersionOptions.Latest).OrderBy(fi => fi.GroupName).OrderBy(fi => fi.SlideOrder);
This will get the most recent version of each Content Item, whether it is published or not

Justin
Marked as answer by LivyChops on 12/3/2014 at 8:17 PM
Dec 4, 2014 at 4:17 AM
"THANKYOU!" Works great now ;) Very much appreciated, Justin - Orchard appears a little complex for me at the moment, but hopefully I can get there - thanks again, Liv
Dec 11, 2014 at 5:21 AM
Edited Dec 11, 2014 at 5:23 AM
Found this in mine as well, this will be a life saver! Thanks!