Steve, the best way to do this is to create a custom template that just prints the field data with no HTML around it. Generally, you would just take a pdb-single-default.php template and strip out all the HTML, leaving the PHP. Then, in the shortcode, you just need to specify the template and the field to show using the “fields” attribute. This is explained in the Other Notes section under “Determining Which Fields are Shown by Each Shortcode”
Instructions for setting up a custom template can be found here.
Thread Starter
saz25
(@saz25)
Hi,
I thank you for your quick reply. I have another question for clarification.
To display a single record using your pdp-single template, how do you specify the particular record? The documentation says by a pdp=1333 argument.
How do you determine pdp id?
What is the syntax of the URL? Is it like this?:
http://www.domain_name.com/page_name/&pdp=1333
If I click on “List Participants” in the Dashboard, I see private IDs. Is that what you mean?
Thanks,
Steve
Sorry, I meant to touch on that…there’s two ways: you can do in the the URL with a ?pdb=1333 or you can do it in the shorcode with the record_id attribute:
[pdb_single record_id=1333]
If you do it in the URL, all the single shortcodes on the page will get their value from that record.
Thread Starter
saz25
(@saz25)
I tried using the URL
with /?pdb=1 but nothing displayed.
I can’t get pdp_single to work at all.
Suggestions ?
Thanks
Steve
Thread Starter
saz25
(@saz25)
Hi again,
I got it to work with the URL.
Now I need to remove the html and just display the contents of a single cell/field. I tried but kept getting fatal errors. I guess I need to learn php.
All I want to do is display a single field for example, if a field is named “town”, why wouldn’t this work?:
<?php echo Participants_Db::$prefix.$this->$town->form_element ?>
Do I just remove all the div classes?
All I want to do is to echo a single character string for a single field within a specific record as indicated by the URL.
Also, can I create more than one pdb_single short codes? If I want a shortcode that displays a field such as longitude, can I clone the first template and just call the new one php-single-latitude.php? How would I reference that shortcode?
Thanks and I’m sorry for all the questions.
Steve
No that won’t work…anyway, too much to explain, I’ll just give you the whole thing, it’s very simple.
I assume you have created your custom template, so just paste this in over everything in your template:
<?php
/*
* template for displaying a single value
*/
?>
<?php
while ($this->have_groups()) : $this->the_group();
while ($this->have_fields()) : $this->the_field();
$this->field->print_value();
endwhile;
endwhile;
?>
Now, to use it, use this in the shortcode… (I named my template “value” change that to the name of your template) and just give it one field to show.
[pdb_single template=”value” fields=”last_name” ]
The reason to do it this way is it allows you to use one template to show any value you want.
Thread Starter
saz25
(@saz25)
This is great. Its a terrific plug-in.
I can now access any specific field I want within a given record.
http://www.domain_name.com/page_name/?pdb=4
The only small change I would make is allow IDs other than numbers. For example, if I could specify IDs to be names such as:
newyork
chicago
baltimore
That way the URL would make sense to a user. Using numbers forces me to make sure I never insert a record between existing records.
Do the IDs need to be numbers that are defined by your code or can they be over-ridden?
Is there no other way, via a URL, to select a specific/single record other than ?pdb=[number] ?
This would be a nice addition:
http://www.domain_name.com/page_name/?town=newyork
(assuming town is a field and newyork is the contents of the town field for a single/unique record.
Otherwise, I love this plugin.
Thanks for your excellent help. I will definitely contribute/donate.
Great work.
Steve
Huh, so you would want multiple records to match the URL? Like a search result?
Thread Starter
saz25
(@saz25)
No,
One record would match the URL.
The name of the town in my application is if fact the unique identifier.
It’s just that I rather use a word (such as town name) in the URL if possible.
It works as it is now, but it might be a bit more user friendly than an id number.
But in any case, one record would march the URL.
Steve
Well, you can do it, but you’d have to do some coding in your WP template to translate the unique field to a record id.
Thread Starter
saz25
(@saz25)
Thanks. I’ll use this as an excuse to teach myself PHP.
I’ve programmed using C and Java for years. It’s about time I learned PHP.
Thanks again,
Steve
Thread Starter
saz25
(@saz25)
Hi,
I’ve made some progress and a few observations.
It seems that I can’t pass any URL arguments to the pdb-list-default.php template. I tried adding a GET command like this:
echo $_GET[“townname”];
It doesn’t work.
However I can pass arguments using the pdb-single templats but only if I have a ?pdb=[number] argument, which I don’t want to do.
So, I think I want to base my work on a modified version of the pdb-list template but with an argument. True?
Shouldn’t I be able to have a URL like this?:
http://www.domain.com/testpage/?townname=newyork
Is it true that the list templates doesn’t accept URL arguments? I don’t see where its called so I can’t see the actual code that invokes the template.
thanks again,
Steve
Thread Starter
saz25
(@saz25)
Hi,
I got it to work. I had to use the pdb-total template since that worked differently than the others and allowed me access to all the records and didn’t require an id in the URL.
Does that make sense?
Thanks again,
Steve
Thread Starter
saz25
(@saz25)
Hi,
In reference to this example that you gave, it works great, though I have a question about context and scope of variables.
<?php
/*
* template for displaying a single value
*/
?>
<?php
while ($this->have_groups()) : $this->the_group();
while ($this->have_fields()) : $this->the_field();
$this->field->print_value();
endwhile;
endwhile;
?>
Instead of that line containing print_value, which prints the contents of the current field, what if I wanted to reference the contents of another field?
For example, in some cases if I use the shortcode for field X, I want to print it, in another case I want to use the shortcode for a field Y but I want to use the contents of field X (in a calculation) in my print/echo statement? But I don’t want to just print it like I did in the first case.
I know I can specify 2 fields in a shortcode, but they would just both print.
I guess what I’m asking is how do I reference any specific field within a pdb_single template that’s called using the ?pdb=123 url?
thanks,
Steve