XF 2.1 How do you access custom thread fields in the database?

Mave

Active member
A thread title can be found using $row['title'];

I created a custom thread field with nbtitle as the identifier.
However $row['nbtitle']; is not working

Can someone explain me what row name custom thread fields would have?
Thanks!
 
I see a 'custom_fields' row, but how do I access the actual custom fields?

G2eIjrY.png
 
$thread->custom_fields['fieldId']
@Jeremy P thanks for answering! However I'm still doing something wrong. I have this now.

foreach ($queryresults as $row) {
$postday = $row['post_date'];
$posttitle = $row['title'];
$message_full = $row['message'];
$nbtitle = $row->custom_fields['nbtitle'];
include ('php/code_gifs.php');
}

In bold what I added, rest already was working. After adding the bold line I get this error:
Notice: Trying to get property 'custom_fields' of non-object on line 135
 
Oh, are you using raw queries? And if so, do you have a good reason? Generally you should be using the finder/entity system where possible.
 
Oh, are you using raw queries? And if so, do you have a good reason? Generally you should be using the finder/entity system where possible.
Using indeed raw queries to automatically populate a website with content. Using a read-only user and pages are cached.
I'd be really thankful if you could help me solve the error :)
 
The column is JSON-encoded and with raw queries you'd need to decode it manually:

PHP:
$customFields = @json_decode($row['custom_fields'], true);
$nbTitle = $customFields['nbTitle'];
 
Last edited:
The column is JSON-encoded and with raw queries you'd need to decode it manually:

PHP:
$customFields = @json_decode($row['customFields'], true);
$nbTitle = $customFields['nbTitle'];
Thank you!

I'm getting no errors now but for some reason I'm only getting empty output while the custom fields are indeed populated.

Q68si6O.png


KciXr8u.png


UoMNrDX.png


gSo6GEk.png
 
Last edited:
Top Bottom