You’ll have to create a custom template. In that template you’d insert code into the loop so that when your private_id field comes around, wrap it in your link.
Hi Roland,
I try to create a link to private_id field as you explain in this topic.
With the code below the variable $private_id is always empty !
Can you help me to find my mistake?
`<?php while ( $this->have_records() ) : $this->the_record(); // each record is one row ?>
<?php
global $wpdb;
$private_id = $wpdb->get_var(‘SELECT p.private_id FROM wp_participants_database p WHERE p.id =’.$this->record->record_id);
?>
<tr>
<?php while( $this->have_fields() ) : $this->the_field(); // each field is one cell ?>
<?php
$url = get_permalink(2854).’?pid=’.$private_id;
if($this->field->name == ‘private_id’) {
$this->field->value = sprintf(‘<a href=”%s”>%s</a>’,$url,$this->field->value);
}
?>`
Many thanks
monpelaud,
Well, since you already have the private_id value, you don’t need to get it from the database…so you can take out the part where you define the variable $private_id altogether.
Now, put your $url variable definition after the if statement in brackets before the “$this_field_value” statement, and use $this->field->value instead of $private_id.
<?php
if($this->field->name == 'private_id') {
$url = get_permalink(2854).'?pid='.$this->field->value;
$this->field->value = sprintf('<a href="%s">%s</a>',$url,$this->field->value);
}
?>
Hi,
Ok, now the value of the variable $value is <a href="http://mysite.com/mywordpress/record/?pid=YFO04">YFO04</a>
.
My issue is that the field private_id is not displayed as a link but as a string.
The string is displayed as is and not as a link.
How to display it as a link ?
Many thanks
OK, looks like I steered you wrong there. What you need to do is similar. Instead of what I told you to do, do this (and I tested this one!). After the line <td class="<?php echo $this->field->name ?>-field">
replace this:
<?php $this->field->print_value() ?>
With this:
<?php
if($this->field->name == 'private_id') {
$url = get_permalink(2854).'?pid='.$this->field->value;
printf('<a href="%s">%s</a>',$url,$this->field->value);
} else $this->field->print_value();
?>
See, that will print the private_id field directly instead of just changing the value and using the print_value() function which strips out HTML.
Hi,
That works perfectly.
Thanks for your help.
Best regards