Jump to content

Schedule change of content


David Beesley
 Share

Recommended Posts

Hi All,

We have a client with a requirement to change the content of one of their pages at midnight on a given day.

I understand there is a module for scheduling the publishing and unpublishing of entire pages, but his would require two separate pages and urls, not good for SEO.

Is there a way/module to schedule changes to a given field on a page?

Link to comment
Share on other sites

I would do it like this:

  1. Duplicate field "field_name_new" and assign to template.
  2. Let client place content in "field_name_new".
  3. Create a PHP script (i.e. /public_html/update_field.php)
    1. Bootstrap ProcessWire
    2. Get the page
    3. Copy the value of "field_name_new" to "field_name" (setAndSave method)
    4. Remove the "field_name_new" field from template and delete field
  4. Schedule a cron job which triggers http://yourdomain.com/update_field.php
  • Like 3
Link to comment
Share on other sites

A bit similar to @arjen's approach:

  1. Duplicate the field as yourfield_replacement labelled "Your Field Label Replacement" and add it to the page's template
  2. Add a new datetime field replace_after labelled "Replace field at" to the template
  3. In site/ready.php, check if $page->replace_after <= current timestamp and $page->yourfield_replacement has content
  4. If yes: replace $page->yourfield with the content of $page->yourfield_replacement, empty $page->yourfield_replacement and save page

This way, editors can edit new content in the added field and schedule replacement whenever they want. The replacement will happen the first time the page in question is accessed at or after the date+time in $page->replace_after.

You can make it a little more elaborate and safe by adding a checkbox to activate the replacement logic and reset it after successful replacement to avoid accidential replacements, which are likely to happen when editors hit "save" after changing the replacement content without having adapted the replace date first.

  • Like 4
Link to comment
Share on other sites

I don't use ProCache (yet, since all the PW sites were highly dynamic ones and speed wasn't an issue so far), so I can't speak from experience, but with ProCache I'd likely set up a script in a (system) cron job instead of a ready.php snippet and interate through all pages with a selector like "replacement_active=1, replacement_date<=$now", then perform the replace as above and save. I believe ProCache should update the cache on its own after page save (correct me if I'm wrong).

  • Like 3
Link to comment
Share on other sites

59 minutes ago, BitPoet said:

I believe ProCache should update the cache on its own after page save (correct me if I'm wrong)

Depends on the settings, but by default: yes, a page save under a Pro Cache handled template updates the entire site.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...