With USP Pro 2.0 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.
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
- Give the custom field a
valuethat specifies the date/time (e.g.,
- 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:
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.
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:
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.
Notice the difference between the custom field
name, “post-date”, and the hidden field
name, “usp-custom-post-date”. This is because USP auto-prepends “usp-custom-” to default custom fields.
Instead of hard-coding a post date, you can let users pick their own dates. Just specify the field
date. For example:
That will display a date-picker in supportive browsers, or fallback to a regular text-input field for older/unsupportive browsers.
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:
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.
In addition to the date/time format used in the previous examples, USP Pro understands relative date formats, such as:
- +1 week
And so forth. Learn more about relative date formats.
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.
See also: Custom Post Status.