joomlajoomla-k2

K2 extra fields access in BT Content slider


I'm trying to access the contents of a K2 extra field inside the BT content slider plugin. If I do

print_r($row->extra_fields);

I get

[{"id":"16","value":"http:\/\/www.youblisher.com\/p\/611670-Test-Intro-to-R\/"}]

I need to access the value, but I've tried everything I could think of with no luck.

Tests I've done (also tried print_r for everything just in case):

echo $row->extra_fields[0]
echo $row->extra_fields[0]->value
echo $row->extra_fields->value
echo $row->extra_fields["value"]

Solution

  • Decode your string into a json object first before trying to access value.

    <?php
    $json = json_decode('[{"id":"16","value":"http:\/\/www.youblisher.com\/p\/611670-Test-   Intro-to-R\/"}]');
    print_r($json[0]->value);
    ?>