Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • croban 25 posts 96 karma points
    Jul 16, 2018 @ 08:52
    croban
    0

    How to get just Published IContent with GetContentOfContentType

    How to get published version from an IContent which has published version but also one version which is saved but not published?

    Calling this method does not return Published version of an IContent

    ApplicationContext.Services.ContentService.GetContentOfContentType(id).Where(f => !f.Trashed && f.Published);
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jul 17, 2018 @ 08:11
    Alex Skrypnyk
    0

    Hi Croban

    Content Service returns IContent always. Use UmbracoHelper for getting IPublishedContent object, like that:

    var publishedContent = Umbraco.TypedContent(id);
    

    Thanks,

    Oleksandr Skrypnyk

  • croban 25 posts 96 karma points
    Jul 26, 2018 @ 06:23
    croban
    0

    Well I know that, but I work on an extension for umbraco and I want to work with service layer not with the cache and this method which I wrote above does not return what I have expected - all icontent which have published version.

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jul 26, 2018 @ 18:50
    Dan Diplo
    0

    Just a guess, but could you use:

    Where(f => !f.Trashed &&  f.Status == global::Umbraco.Core.Models.ContentStatus.Published);
    

    ?

  • croban 25 posts 96 karma points
    Aug 06, 2018 @ 09:50
    croban
    0

    Hi Dan

    This does not help also :(...

    I must explicitly check if IContent is Published and if not than i have to take ByVersion. e.g.:

    var data = ApplicationContext.Current.Services.ContentService.GetContentOfContentType(id).Where(f => !f.Trashed && f.HasPublishedVersion);
    
    foreach (var iContent in data)
    {
    
        //if version is not published 
        if (!iContent.Published) {
        //take published version and overwrite iContent
        iContent = ApplicationContext.Current.Services.ContentService.GetByVersion(iContent.PublishedVersionGuid);
        }   
    
    .... do the job
    

    }

Please Sign in or register to post replies

Write your reply to:

Draft