Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Shows how to display a timestamp as a public field in a Participants Database single record display.
* @name pdb single template show timestamp
* @version 2.0
* template for displaying a single record
if ( $this->participant_id > 0 ) :
<div class="wrap <?php echo $this->wrap_class ?>">
<?php while ( $this->have_groups() ) : $this->the_group(); ?>
<div class="section <?php $this->group->print_class() ?>" id="<?php echo Participants_Db::$prefix.$this->group->name ?>">
<?php $this->group->print_title( '<h2 class="pdb-group-title">', '</h2>' ) ?>
<?php $this->group->print_description() ?>
<?php while ( $this->have_fields() ) : $this->the_field();
// CSS class for empty fields
$empty_class = $this->get_empty_class( $this->field );
// the public field for showing the timestamp is named "updated_timestamp"
if ( $this->field->name() === 'updated_timestamp' ) {
$this->field->set_value( $this->participant_values['date_updated'] );
<dl class="<?php echo Participants_Db::$prefix.$this->field->name.' '.$this->field->form_element.' '.$empty_class?>">
<dt class="<?php echo $this->field->name.' '.$empty_class?>"><?php $this->field->print_label() ?></dt>
<dd class="<?php echo $this->field->name.' '.$empty_class?>"><?php $this->field->print_value() ?></dd>
<?php endwhile; // end of the fields loop ?>
<?php endwhile; // end of the groups loop ?>
<?php else : // content to show if no record is found ?>
<?php $error_message = Participants_Db::plugin_setting( 'no_record_error_message', '' );
if ( ! empty( $error_message ) ) : ?>
<p class="alert alert-error"><?php echo $error_message ?></p>
<?php endif ?>
<?php endif ?>

This comment has been minimized.

Copy link
Owner Author

@xnau xnau commented Mar 17, 2021

This demonstrates the use of a custom template for showing a value from the record data as a public field.

The template should be called with a shortcode like this: [pdb_single template=show-timestamp]

If you're unfamiliar with the use of Participants Database custom templates read this article:

Using Participants Database Custom Templates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment