Is it possible to allow the setting of the publish date of an item (news article) in the past?
I am creating a new Umbraco site (my first. And I absolutely love it!) and porting content from our existing site, so we have articles going back a few years. I have added a publishDate field in order to get the date properly displayed, but because of examine, I cannot sort on this field in search results and would like the results to be in descending date order. So it’s not really a viable option.
I’ve tried writing an index component to convert the publishDate field to ticks, but can’t get this working either. - Even after rebuilding the index I don’t see any more properties - But that is a separate question I’ll be asking.
I’ve unpublished the article and tried a scheduled publish, but I get an error saying it can’t be published in the past? Is there anyway, short of a SQL query, to achieve this?
As far as I’m aware, you can’t change the publish date, or create date, however if you add a property such as “date picker” then you will be able to render and use this. It should work the same and be pretty simple to set up.
using Examine;
using Examine.Lucene;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
namespace Umbraco.Docs.Samples.Web.CustomIndexing;
public class ConfigureExternalIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
public void Configure(string name, LuceneDirectoryIndexOptions options)
{
if (name.Equals(Constants.UmbracoIndexes.ExternalIndexName))
{
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("publishDate", FieldDefinitionTypes.DateTime));
}
}
// Part of the interface, but does not need to be implemented for this.
public void Configure(LuceneDirectoryIndexOptions options)
{
throw new System.NotImplementedException();
}
}
public class ExamineOptionsComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
// Custom Examine configuration
builder.Services.ConfigureOptions<ConfigureExternalIndexOptions >();
}
}
As it’s a news Item you probably don’t want to use the umbraco publish date.. as that would change everytime an editor touched the content..
So it’s probably the CreateDate you’d use from the native properties again not ideal… or just as you’ve done a dedicated custom property that is the date to be associated with the news release.
Which is what you currently have..
If you really did want to use the CreateDate might be simpler to use a package that allows import mapping…
maybe too late now, but in terms of porting content… CMSImport | Umbraco Marketplace
Allows you to well import from various types, and you can map to the umbraco core CreateDate from one of your properties..
Also uSync | Umbraco Marketplace
could be of use.. creating a content export gives you a config file that you can manipulate and reimport after setting the createDate..
As both these packages leverage setting a createDate, also should be possible to write code to set the CreateDate yourself.