podio ,如何获取具有特定字段值的所有项目

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

我需要将所有项目的 active-house 设置为活动状态,所以不要获取所有项目并测试 active-house 是否设置为活动状态,如下所示:

    $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;
                    }
                }

            }
    }

我只需要过滤那些 active-house 设置为 active 的,我该怎么做?

1) 手工方式 — 使用filter by view. First you set up filters and save them as a view in Podio (manually or via API)。它可以是团队视图,也可以是私人视图,都没有关系。然后您就可以从该视图中获得已过滤的项目:

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

在此处查看文档:https://developers.podio.com/doc/items/filter-items-by-view-4540284

如果您希望 users/admins 无需任何编码即可控制脚本的结果,这种方法很有用 — 他们只需编辑视图即可。

2) API-only way — 在过滤器中使用字段。请注意,并非所有字段类型都可用于过滤,即不能使用文本字段。以下是多选类别字段的示例:

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

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

请参阅有关如何筛选其他字段类型的文档:https://developers.podio.com/doc/filters