As it’s fairly well known, it is possible to schedule Posts in WordPress for publishing.
Also Attachments are actually Posts (in the more internal, technical meaning).
So the question that bothers me right now is: Is it possible to schedule attachments as well? Like for example that a Photo-Gallery grows over time?
My idea is that you can setup a post date for the attachments. This can be done using
attachment_fields_to_edit
to show the UI (is possible use thetouch_time
internal function).After that, you can filter all the attachments query to show only the attachments with a past or current date.
So
Now on the attachment page you’ll see something like:
Now let’s set post date on attachment save:
When attachment is saved, the post date is set to whatever you set on date fields.
However, attachments are all visible, no matter the date, because WordPress does not check the date on attachments queries. Let’s add a filter to where clause for that:
Now in a shortcode for gallery (or wherever you want) be sure to use
WP_Query
setting up the post type argument to'attachment'
.On standard
[gallery]
shortcode this will not work because it usesget_children
where query filters are suppressed, so you have to create a custom shortcode or overwrite the default.Create the complete gallery at once, use a custom shortcode handler for it.
In your shortcode handler, just count the attachments for an advent calendar, or look up a post meta for the attachment. Replace the image with a placeholder or hide it completely, if it should not be seen yet.
An attachment is public the moment is is uploaded, because WordPress is not involved in the direct file request.