Keyword

Extrafield Select Type: How to get right value?

  • Fábio Jordan
  • Fábio Jordan's Avatar Topic Author
  • Offline
  • Senior Member
  • Nothing like a good coffee to make a better web
More
1 year 3 months ago #181088 by Fábio Jordan
Hi, there! I'm using a plugin to relate some K2 items. It can fetch most part of the data from K2 Database, but it does not work properly to get data from K2 Extrafield Select Type.

Right now, I'm using this code to retrieve the Extrafield values:
    <?php $extraFld = array();
    if ($XTlinkedItem->extra_fields)
    {
    $extraFields = json_decode($XTlinkedItem->extra_fields, false);
    foreach ($extraFields as $key=>$extraField)
    {
    $extraFld[ $extraField->id ] = $extraField->value;
    }
    } ?>

And then using this shortcode I can show the Extrafield in Frontend:
<?php echo $extraFld[10] ?>

It works fine for Extrafields like Text or Date. But it won't show the right value for Select Type.

In K2 Database, this Extrafield has those names and values:
[{"name":"i3-10110U","value":"2","target":null,"alias":"modelointel","required":0,"showNull":1},{"name":"i3-1005G1","value":"3","target":null,"alias":"modelointel","required":0,"showNull":1}]

And when I save an item with this Extrafield, the itemt gets this id and value:
{"id":"10","value":"3"}

So, instead of showing the name "i3-1005G1", the plugin is showing just a number, in this case, the value "3", since its reading this in the K2 items table. My question is: how can I link those two informations so that the plugin can show the correct name?

Thanks in advance!

Regards.
 
Attachments:

Please Log in or Create an account to join the conversation.

  • Fábio Jordan
  • Fábio Jordan's Avatar Topic Author
  • Offline
  • Senior Member
  • Nothing like a good coffee to make a better web
More
1 year 3 months ago #181102 by Fábio Jordan
Replied by Fábio Jordan on topic Extrafield Select Type: How to get right value?
Well, a quick reply to inform the problem is solved (not in the best way, but I managed how to get the values).

I'm using arrays with the same values of the extrafields, like this:
$cpus = array('CPU', 'Not informed', 'Intel Core i3', Intel Core i5', 'Intel Core i7', Intel Core i9')

Then using echo to retrieve the proper value:
$modelCPUi = $extraFld[10];
echo $cpus[$modelCPUi]

It needs some hard work since I have lots of Extrafields, but at least it's a workaround.

 

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum