Jump to content

Recommended Posts

Posted

Currently there is no way for an editor to change those fields. Both are static. Even from the API.

But sometimes – especially when using a news site or some kind of blog – you have to use those fields a lot.

It would be nice if the fields become editable, so you can change the creation date for example.

  • Like 1
Posted

Think of these as 'system' values. You only create a page once, this value never changes. Same with modified.

On top of that you can add as many date time (or time) fields you want, like, 'created_date', 'publish_date', 'unpublish_date' etc.

Posted

See them as "not" fields but a system property that is consistent with when a user edited or created a page that never changes. Don't try to use this as the article created or modified, instead I advise to use custom datetime fields.

This makes sure you get a "real" creation and modified date you can rely on for maintenance or rechecking what happened when and so on. Many times this can be good to have. Adding custom date fields for the editor is then only used for output.

  • Like 1
Posted

Consider that users, templates, permissions roles etc. are in fact also pages. Not a good idea to give editors the possibiliy to mess up this.
Follow Somas recommendation and build some additional custom datetime fields.
If you need the original values as initial value, you could do this in your template

$page->of(false);
$page->set('CustomFieldModified', $page->modified);
$page->set('CustomFieldCreated', $page->created);
$page->save();

echo $page->CustomFieldCreated;
Posted

@kixe: Maybe add check to prevent that this will be overwritten.

$page->of(false);
if($page->CustomFieldModified == '') $page->set('CustomFieldModified', $page->modified);
if($page->CustomFieldCreated == '') $page->set('CustomFieldCreated', $page->created);
$page->save();
  • Like 1
  • 6 months later...
Posted

I realize setting the created date programmatically is very important when migrating content from an old site (I do that now, from drupal). 

I would very much be able to do that at least from the API. So, is SQL the only option?

Posted

I realize setting the created date programmatically is very important when migrating content from an old site (I do that now, from drupal). 

I would very much be able to do that at least from the API. So, is SQL the only option?

There is an option for changing the "created" date via the API using quiet mode:

$page->created = $timestamp
$page->save(array('quiet' => true));

This only works for created though, not modified. This is what I use for modified - make sure you do this after the last $page->save() or it will be overwritten.

$sql = "UPDATE `pages` SET `modified` = '".date('Y-m-d H:i:s', $timestamp)."' WHERE `id` = '".$page->id."';";
$update = wire('db')->query($sql);
  • Like 4
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...