Andreea Onica
Andreea Onica

Reputation: 357

podio , How do I get all items with certain field value

I need to get all items with active-house set to active, So instead of getting all items and test if the active-house is set to active, like this:

    $items = PodioItem::filter($app_id,array('external_id'=>array('active-house')));
    $today_active=array();
    foreach($items as $item){
    $fields=$item->fields;

            foreach($fields as $f){
                if($f->external_id=='active-house'){
                    print_r($f->values);
                    if($f->values[0]['text']=='Active'){
                        $today_active[]=$item->title;
                    }
                }

            }
    }

I need to filter only the ones with active-house set to active, how can I do this?

Upvotes: 0

Views: 886

Answers (1)

Eugen Baryshnikau
Eugen Baryshnikau

Reputation: 435

1) Handmade way — use filter by view. First you set up filters and save them as a view in Podio (manually or via API). It could be a team view or a private one, it does not matter. And then you just get already filtered items from that view:

    $items = PodioItem::filter_by_view( $app_id, $view_id, $attributes);

See the documentation here: https://developers.podio.com/doc/items/filter-items-by-view-4540284

This way is useful if you want users/admins to control results of your script without any coding — they can just edit the view.

2) API-only way — use fields in filter. Note that not all field types can be used for filtering, i.e. text fields cannot be used. Here is an example for a category field with multi-selection:

    $attributes = array(
        "filters" => array(
            $field_id => array(1,2,4) // 1,2,4 - IDs of needed category values
        )
    );

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

See the documentation on how to filter other field types: https://developers.podio.com/doc/filters

Upvotes: 2

Related Questions