Support » Plugin: Participants Database » Add a link on private_id field

  • Resolved monpelaud

    (@monpelaud)


    Hi,

    I would like to display the private_id field in list of records to access the [pdb_record] form.
    I use this shortcode [pdb_list fields=”first_name,last_name,last_name,city,state,private_id”] in a WordPress page.
    The private_id is displayed but it’s displayed without link to the [pdb_record].
    Is it possible to add a link on private_id field to access the [pdb_record] form ?

    Thanks for your help

    http://wordpress.org/extend/plugins/participants-database/

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

    (@xnau)

    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.

    Thread Starter monpelaud

    (@monpelaud)

    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

    Plugin Author xnau webdesign

    (@xnau)

    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);
    }
    ?>
    Thread Starter monpelaud

    (@monpelaud)

    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

    Plugin Author xnau webdesign

    (@xnau)

    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.

    Thread Starter monpelaud

    (@monpelaud)

    Hi,

    That works perfectly.
    Thanks for your help.

    Best regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add a link on private_id field’ is closed to new replies.