David Beesley Posted October 19, 2016 Share Posted October 19, 2016 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 More sharing options...
Marty Walker Posted October 19, 2016 Share Posted October 19, 2016 Was looking at something similar today. In my case I'm using this approach http://processwire-recipes.com/recipes/duplicate-content-between-fields/ to copy info between fields. 2 Link to comment Share on other sites More sharing options...
arjen Posted October 19, 2016 Share Posted October 19, 2016 I would do it like this: Duplicate field "field_name_new" and assign to template. Let client place content in "field_name_new". Create a PHP script (i.e. /public_html/update_field.php) Bootstrap ProcessWire Get the page Copy the value of "field_name_new" to "field_name" (setAndSave method) Remove the "field_name_new" field from template and delete field Schedule a cron job which triggers http://yourdomain.com/update_field.php 3 Link to comment Share on other sites More sharing options...
BitPoet Posted October 19, 2016 Share Posted October 19, 2016 A bit similar to @arjen's approach: Duplicate the field as yourfield_replacement labelled "Your Field Label Replacement" and add it to the page's template Add a new datetime field replace_after labelled "Replace field at" to the template In site/ready.php, check if $page->replace_after <= current timestamp and $page->yourfield_replacement has content 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. 4 Link to comment Share on other sites More sharing options...
arjen Posted October 19, 2016 Share Posted October 19, 2016 Nice @BitPoet, seems more elegant en better usable. How would you handle this situation where ProCache is enabled? Link to comment Share on other sites More sharing options...
BitPoet Posted October 19, 2016 Share Posted October 19, 2016 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). 3 Link to comment Share on other sites More sharing options...
David Beesley Posted October 19, 2016 Author Share Posted October 19, 2016 Some cracking solutions folks. Cheers Link to comment Share on other sites More sharing options...
arjen Posted October 19, 2016 Share Posted October 19, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now