Recently a user asked how to set up an auto-expiring USP Form for USP Pro. This is useful for running contests and time-sensitive post submissions. This tutorial explains a basic technique that can help make it happen.

Step 1

Add the following code to your theme’s functions.php file (or add via simple plugin):

// conditionally hide post content based on custom field
function usp_pro_conditional_content_display($content) {
	
	$date = get_post_meta(get_the_ID(), 'usp-form-date', true);
	
	if (strtotime($date) >= strtotime('now')) {
		
		return $content;
		
	}
	
}
add_filter('the_content', 'usp_pro_conditional_content_display');

This function checks for a custom field named usp-form-date on the page that displays the USP Form. No modifications are required, but you are encouraged to customize this snippet to suit any specific requirements. Note that the custom field must have a date value that is in Unix/POSIX time format.

Step 2

On the “Edit Page” screen of the page that displays the USP Form, add a custom field named usp-form-date. Give this custom field a date value in Unix/POSIX format, for example: 2018-05-05 10:35. Note: this is a 24-hour time format.

Save changes and done.

Once everything is in place, the content of the page (including the USP Form) will be displayed only until the specified date/time is reached. Form then on, or until the custom field is removed, the form will not be displayed.