This project is read-only.

Select all published content items of type

Topics: Customizing Orchard
Oct 18, 2013 at 7:59 PM
I have two parts to my question. I'm very new to Orchard so I believe I'm just not asking the right question in my search for answers.

First, I'm building an aggregation widget and have a custom content type that will store the values to aggregate. I can't seem to get my head around executing a query against ContentManager that will let me select all published items. Is this just automatic?

Second, my content item has the TitlePart assigned and I can't figure how to programmatically get the title value when walking the list of content items of my specific type.

Thanks for any pointers.
Oct 18, 2013 at 8:48 PM
Got it. For others who may have the question here is the simple solution:
var items = _contentManager.Query<MyPart>(VersionOptions.Published).List();

foreach (var item in items) 
   var title = item.As<TitlePart>().Title;
Oct 18, 2013 at 11:15 PM
  1. Use contentManager.Query<YOURPART>() which will give you only published content
  2. Don't do that this way. Here you are loading ALL your content items. There is no reason you would like to do that. There are actually but can't be written on a public forum ;)