Skip to content

Instantly share code, notes, and snippets.

@xnau

xnau/pdb-default-date.php

Last active Feb 8, 2021
Embed
What would you like to do?
Shows how to set the default date for a specific date field in Participants Database
<?php
/**
* Plugin Name: PDB Default Date
* Description: sets the default date for a specific date field
*/
add_action( 'pdb-before_display_form_input', 'xnau_set_default_date' );
/**
*
* @param PDb_Field_Item $field
*/
function xnau_set_default_date( $field )
{
// set this to the name of the field you want to set the default date on
$date_field = 'date_acquired';
if ( $field->name() === $date_field && $field->is_empty() ) {
/**
* this sets the date relative to the current date
*
* @see https://www.php.net/manual/en/function.strtotime.php
*/
$field->value = strtotime( '-1 month' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment