1
votes

When using the Podio PHP API and after getting an item collection using:

$item_collection = PodioItem::filter( $app_id, $attributes );

How can I get the value(s) of a field with an external_id of, for example, email?

Currently I loop through all the items like this:

$items = [];
foreach ($item_collection as $item) {
    $email = "";
    foreach ( $item->fields as $field ) {                   
        if( $field->external_id == "email") {
            $email = trim($field->values);
        } //repeat for each field eg 'name'
    }
    $items[] = array (
        'email' => $email,
        'name'  => $name //etc
   );
}

Is there a way to directly get the field value without looping through all the fields in the whole collection of items?

Using PodioItem::get_field_value obviously makes another request which seems counter to getting all the items from PodioItem::filter.

1
i dont know the Podio API, but i would assume that the "email" attribute is always on the same index, so you could acess it dirctly. Else you you could use break to stop the foreach-loop after you found the attribute for a small performance boostfehrlich
Unfortunately, the index isn't the same for all items - if a particular item doesn't have a value for that field then it isn't returned.James

1 Answers

0
votes