Using App.WorkWith to get blogPosts

Posted by Community Admin on 04-Aug-2018 19:17

Using App.WorkWith to get blogPosts

All Replies

Posted by Community Admin on 30-Jul-2014 00:00

I'm attempting to get blogPosts... this part works. I attempt to get blog posts that are published... this also works. But then I attempt to get blogPosts and exclude posts that are expired, and this fails. The only way i can get posts that are published and not expired is to use the 'unpublish' setting for a post. I checked the database and there are 2 fields for expiredDate. Also, I was going to get posts that are before an unpublished date but there is no method for this. 

var blogList = App.WorkWith().Blog(blogId).BlogPosts()
                .Where(b => b.Status == ContentLifecycleStatus.Live && b.PublicationDate <= dateTimeNow                     && (b.ExpirationDate >= dateTimeNow || b.ExpirationDate.Equals(null)))
               .Get().ToList();
or
var posts = from p in App.WorkWith().BlogPosts()
                        where p.Parent.Title == "Testing"
                        && (p.ExpirationDate >= dateTimeNow || p.ExpirationDate == null)
                        orderby p.Title
                        select p;

Is the WorkWith fluent method properly wired to use expired field? I'm asking because I can't seem to find an unpublished attribute. 

Posted by Community Admin on 04-Aug-2014 00:00

Hi Richard,

Can you please try to use the Published() filter available for the fluent API, for example:

App.WorkWith().BlogPosts().Published().Get();

The code above will retrieve all the blog posts which are published, visible on the frontend and their ExpirationDate equals to null or is set for a date after DateTime.Now.

You may also take a look at the following forum post from more details on this matter.

I hope this information helps. Please let me know if you need any further assistance.

Regards,
Sabrie Nedzhip
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed