Copied to clipboard

Flag this post as spam?

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


  • Sowndar M 54 posts 148 karma points
    Jan 23, 2020 @ 14:37
    Sowndar M
    0

    Change the created date for specific post won't work

    I tried to change the created date for the specific post in Umbraco 8. after some time it changes back to original published date

    select * from umbracoNode where id='7541';
    update umbracoNode SET createDate = '2019-03-01 13:38:32.890' where id = '7541'
    
  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jan 23, 2020 @ 15:54
    Kevin Jump
    1

    Hi,

    Umbraco does quite a lot of caching of values, so changing them in the database isn't necceserlly going to stick, because if someone later comes along and loads the page though the back office it might get those values from the cache - and then save them.

    Its better to change these values via the API - because that will update the cache too, and it will all have a better chance of sticking.

    For what you want to do you could use the content service :

    as a quick example this would set the date via a Api Controller

    public class SetContentDateApiController: UmbracoAuthorizedApiController
    {
        [HttpGet]
        public bool SetContentDate(int id)
        {
            var item = Services.ContentService.GetById(id);
            if (item == null) throw new KeyNotFoundException(nameof(id));
            item.CreateDate = new DateTime(2019, 03, 01, 13, 38, 32, 890);
            Services.ContentService.Save(item);
            return true;
        }
    }
    

    Then you would be able to call this by visiting: http://yoursite/umbraco/backoffice/api/SetContentDateApi/SetContentDate/7514

Please Sign in or register to post replies

Write your reply to:

Draft