Copied to clipboard

Flag this post as spam?

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


  • Marc-André 63 posts 279 karma points
    Aug 19, 2019 @ 15:00
    Marc-André
    0

    Get unpublished content?

    Hi!

    Is there anyway to get a value from an unpublished node?

    Here's my code :

    public JsonResult<String> GetData()
        {
          var id = HttpContext.Current.Request­.QueryString["id"];
          dynamic properties = Umbraco.Content(Convert.ToInt32(id));
    
          return Json(properties.Data);
        }
    

    If I go to the BackOffice and chage the value of "Data" and just Save It, my method always return the last published version instead of my new saved, but unpublished one.

    Thanks!

  • Amir Khan 1287 posts 2744 karma points
    Aug 19, 2019 @ 15:40
    Amir Khan
    100

    Would this work? I've used this to query for reviews tagged to unpublished locations, worked great for me.

    https://our.umbraco.com/forum/developers/api-questions/49595-Query-unpublished-nodes-by-property-value

    There's a check in the API to see if something is published, you could just filter for the opposite.

  • Marc-André 63 posts 279 karma points
    Aug 19, 2019 @ 15:47
    Marc-André
    0

    I tried it, but when I use the getValue method from the IContent returned by the query, it always return me null.

    That's said, I don't think it will see the difference between my published value and my saved value.

  • Marc-André 63 posts 279 karma points
    Aug 27, 2019 @ 11:47
    Marc-André
    0

    I finally get this to work with the API. Yeah!

  • SteveV 54 posts 240 karma points
    Aug 27, 2019 @ 12:11
    SteveV
    0

    Keep in mind if you use the ContentService you are talking directly to the database. This approach might not scale if your site receives a lot of visitors.

  • Marc-André 63 posts 279 karma points
    Aug 27, 2019 @ 12:12
    Marc-André
    0

    You're right! Is there a more performant way to do this?

  • Jothipriya G 8 posts 110 karma points
    Feb 23, 2022 @ 15:34
    Jothipriya G
    1

    Hi Marc-André,

    I'm the new to Umbraco and I'm struggling to get the unpublished contents. Kindly guide me to get the unpublished contents.

    I have created a document type article and article items as mentioned in Our Umbraco tutorial. In content section I have created a five number of article items as a blog and unpublished two of them. I'm getting three published article items in the site. Now I want to get the unpublished contents instead of published one. How I can do this???

    Kindly guide to do this.

  • Enkosi 11 posts 86 karma points
    Oct 17, 2023 @ 16:20
    Enkosi
    0

    For others who may come across this you can do the following:

    var results = _services.ContentService
    .GetPagedDescendants(contentAtRoot.Id, 0, int.MaxValue, out long totalRecords);
    

    _service is ServiceContext _services which can be injected into your controller if you are using a controller.

    You can get descendants or children. This is not optimal at all so use it wisely.

Please Sign in or register to post replies

Write your reply to:

Draft