Getting field values from item through PHP
AnsweredHello everyone,
I've got a question. I'm having trouble getting specific values of items through PHP. After doing some research I've managed to pull data by using this for example:
$item = PodioItem::filter(7140799);
echo $item["items"][0]->attributes["fields"][1]->attributes["values"][0]["value"];
This works fine but its a hassle finding each and every value inside the PHP array. Is there a better way to get a specific value? By searching for the field_id or something? I've tried this as well but I keep getting the error "Invalid value {"field_id": 55428207}: must be object":
$filters = array(
array(
'field_id' => 55428207)
);
$item = PodioItem::filter(7140799, $filters);
I hope someone can help me!
Thanks in advance,
Robert
-
Oh my god thank you this is exactly what I was looking for! I searched everywhere for this, maybe you should add this to the examples in the future as its pretty useful!
For everyone else running into this in the future, this will return an array. So you will still need to define which value of the field you need. For example if the field is the contact info with the name, this will give you the name:
echo $item["items"][0]->field(YOUR_FIELD_ID)->values[0]["value"]["name"];If your field is a picture, this will get you the thumbnail URL:
echo $item["items"][0]->field(YOUR_FIELD_ID)->values[0]["value"]["thumbnail_link"];Thanks again for the fast answer Andreas you are a life saver!
-
One more question...is there a way to sort everything by a specific field_id? Lets say I want to retrieve every items of an app and order everything by field_id 55428207 which is a contact and the value name? This would be the structure: $item["items"][0]->field(55428207)->values[0]["value"]["name"]
Ive tried playing around with order_by parameters but it didnt work
Thanks! -
You can sort on some fields but not all. You can see the a list in the documentation: https://developers.podio.com/doc/filters
Please sign in to leave a comment.
Comments
4 comments