Support » Plugin: Participants Database » [Plugin: Participants Database] Populate Specific Field in pdb_single

  • Roland –

    Hello and thanks for this fantastic plugin. It does a wonder for my organization.

    I want to replace individual member pages with profiles generated by pdb_single. I developed a template to this end that looks like a photo business card with a bio below. Unfortunately that means the loop call in the default doesn’t help me, as I need to add specific field entries in specific places

    Is there a specific variable/syntax within the plugin that will echo field value by specifying field name for the displayed record (as indicated in the $_GET[‘pdb’] appendage)? If not, can you recommend an appropriate top-of-page foreach loop to populate an array( [name] => value ) with all fields, even those not set to display?

    TIA for any help you can offer…I’m beyond novice at php.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author xnau webdesign



    If I am understanding what you want to do correctly, you shouldn’t have any trouble adding or changing any field as it loops through the fields. Just set up a switch statement inside the inner ($group-fields) loop (before the part of the template that actually displays the field) something like this:

    switch ( $field->name ) {
        case 'first_name': // this is the name of the field you want to alter the value of
            $field->value = 'new value for the field';
        default: // everything else goes here and is left alone

    You can alter the value of any field like this. Check to see how a switch statement should be structured.

    hope this gets you on the right track

    Maybe I’m misreading, but I don’t think this addresses my issue. I don’t want to edit any fields or alter the loop, I want to remove the loop entirely. When you go to the roster on the page with the [pdb_list] shortcode, and click a link to view an individual record, I have a template I want the record to display in, which requires that I echo each individual value I want in the place that I want it. The loop function can’t do that, so far as I’m aware.

    What I need to know is if, with the relevant universal functions in participants-database.php, to directly echo the value by the variable name, and what the syntax would be, or if I need to add code or modify the loop to populate an array instead of displaying, and then echo the values from the array.



    Plugin Author xnau webdesign



    The loop is simply an efficient way to deal with a large set of values that need to be all dealt with similarly. You can do what you want to do with the loop, but you don’t have to use it. In the default template, there’s a function call:

    Participants_Db::single_record_fields( $id, $exclude )

    This returns a large multi-dimensional array with all the fields organized into groups. If you put something like the following in your template (temporarily, just to show the data), you’ll see the array and that will tell you how to find any value you want:

    $all_fields = Participants_Db::single_record_fields( $id, $exclude );
    echo '<pre>'.print_r( $all_fields, true ).'</pre>';

    Try this, it will make it clearer for you.

    Thanks. The issue was that the resulting multidimensional array had too many layers to access the record values without needing a sort process to get through the groups into the field level. I ended up adding a mod of the s_r_f function that stripped out the groups level:

    public function custom_record_fields( $id ) {
    	global $wpdb;
    	// assemble field list
    	$sql = '	SELECT, v.title, v.form_element
    			FROM '.self::$fields_table.' v
    			ORDER BY v.order ';
    	$fields = $wpdb->get_results( $sql, OBJECT_K );
    	// get field values
    	foreach( $fields as $datum) {
            	$grab =	$wpdb->get_row( "SELECT <code>".$datum->name."</code>
    				FROM ".self::$participants_table."
    				WHERE <code>id</code> = '".$id."' ", ARRAY_N ) ;
    		$datum->value = $grab[0] ;
    	return $fields;

    With that, the template can call values with:

    <?php	$records = Participants_Db::custom_record_fields ( $id ) ; ?>
    <?php	echo $records[*field_name*]->value ; ?>

    If there’s a neater way to do it feel free to share, but for now it’s working.

    Plugin Author xnau webdesign



    Looks good. You’re right, dragging an individual value out of that nested array would be cumbersome. You solution is elegant.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Participants Database] Populate Specific Field in pdb_single’ is closed to new replies.