View Full Version : How to recall an additional profile field in template other than postbit?
bzcomputers
10-03-2012, 01:34 AM
I have an additional profile field "12" that I'm using in the post bit just fine with this code:
{vb:raw post.field12}
What I need to do is recall this information in the templates - threadbit, forumhome_lastpostby, FORUMHOME and FORUMDISPLAY.
The code above will not work in the other templates, what do I need to do to be able to call up this info?
Edit: I believe the issue may be in linking the thread to the user field - linking [userid] to [postuserid]. I could be wrong.
Edit: I believe the issue may be in linking the thread to the user field - linking [userid] to [postuserid]. I could be wrong.
Yeah, the issue is that the forum displays use data from the forum and thread tables, and it only includes the username and userid. I think that's why there is no "markup" for user names on those pages.
In the case of the threads displayed in forumdisplay, you could use a plugin on hook forumdisplay_query to add a JOIN of the userfield table to get field12, but you can only do it for either the thread starter or the last poster (since I believe you can only JOIN each table once). Otherwise you'd need to do separate queries which isn't difficult, but will add one query per thread displayed (or per user, if you figure out a way to cache the results).
For forumhome, same issue except I believe the information comes from the forum cache (so I don't think there's a hook to do a JOIN like in the forumdisplay case).
bzcomputers
10-03-2012, 08:09 PM
Thanks for that.
Still a little on the novice side with vB so a couple questions on your answer.
The linking of the thread starter to field12 will definitely work in my case. I just need the field12 information for threads which are in forums that actually don't allow additional posts (so the thread starter and last poster will be the same in all instances too).
I do understand selecting the hook location for the plugin but have no clue what the actual plugin code would be to do a JOIN between the user-field12 and thread-postuserid.
Thanks for pointing me in the right direction.
You'd do something like this, using hook forumdisplay_query:
$hook_query_fields .= ', userfield.field12 ';
$hook_query_joins .= ' LEFT JOIN ' . TABLE_PREFIX . 'userfield AS userfield ON (userfield.userid = thread.postuserid) ';
Hopefully that will do it for you.
Edit: Then of course you'd probably use {vb:raw thread.field12} in the template.
bzcomputers
10-03-2012, 10:26 PM
Thanks again kh99 - got it working perfectly with your help.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.