With USP Pro version 2.0 and better, you can schedule future posts and set past dates (or any date) on submitted posts. This tutorial explains the steps required to make it happen.
Scheduled Posts
Any form that you create with USP Pro can be set to submit posts that have a future/scheduled post date. Here are the steps:
- In your form, create a custom field with the
name
defined aspost-date
(i.e.,name#post-date
). - Give the custom field a
value
that specifies the date/time (e.g.,value#2050-07-04 23:59:59
) - Add the custom field to the form using its shortcode (e.g.,
[usp_custom_field form="72" id="2"]
).
That’s all there is to it. After implementing, any posts that you submit with the form will have the specified date/time as the Post Date, and will be “Scheduled” for publishing at that time. For example, if you add the following custom field:
name#post-date|value#2050-07-04 23:59:59
The submitted post will be scheduled for publishing just before midnight on July 4th, 2050. You can change the date to whatever is required, but make sure to keep the same date/time format.
Hidden Field
Note that the custom field that we have just defined will be displayed/visible in the form, which means that the user can modify it. To prevent this, we can make it a hidden field by adding type#hidden
to the custom-field definition, like so:
name#post-date|type#hidden|value#2050-07-04 23:59:59
Alternately, we can skip the custom field altogether and manually add the markup for a hidden field. So rather than fussing with a custom field, we can add the following markup to the form:
<input name="usp-custom-post-date" type="hidden" value="2050-07-04 23:59:59">
Learn more about setting values with hidden fields.
name
, “post-date”, and the hidden field name
, “usp-custom-post-date”. This is because USP auto-prepends “usp-custom-” to default custom fields.User Preference
Instead of hard-coding a post date, you can let users pick their own dates. Just specify the field type
as date
. For example:
field#input|name#post-date|type#date|value#2050-07-04 23:59:59
That will display a date-picker in supportive browsers, or fallback to a regular text-input field for older/unsupportive browsers. To leave the date field blank (with no default date set), simply omit the value
attribute, like so:
field#input|name#post-date|type#date
Past Posts
Custom Post Dates do not need to be future/scheduled; you can set any date/time that is desired. For example, to set a Post Date that is past we can use the following value for the post-date
custom field:
name#post-date|value#2000-01-01 12:00:01
Or via hidden field:
<input name="usp-custom-post-date" type="hidden" value="2000-01-01 12:00:01">
Conceivably, it would be possible to create a custom select field that enables the visitor to select whichever date they prefer from a dropdown menu. Just a thought.
Date/Time Format
In addition to the date/time format used in the previous examples, USP Pro understands relative date formats, such as:
- now
- yesterday
- +1 week
And so forth. Learn more about relative date formats.
Further Infos
A couple of useful notes. In the WordPress Admin Area, you can see which dates are used and their respective formats by visiting WP General Settings ▸ Timezone.
Also, you can use the usp_post_date_offset
filter hook to customize the default Time Zone Offset. For example:
apply_filters('usp_post_date_offset', get_option('gmt_offset') * 3600);
This shouldn’t be necessary as the plugin works with WordPress to handle all of the date/time stuff automatically, but the functionality is there if needed.