Guest
03 Dec 2013 15:27

I have been using the Cobalt API and am stuck.

I have used the API to return specific records. These records have a child field and have many children. How can I filter these children results?

Here is the code I am using to get the array of records.

$areas = $api->records(

    $section_id = 4, //ID of Directory 

    $orderby='r.title ASC', 

    $limit=1000,

    $ids = $record_list //my array of values

);

Each item in this array has children(using the relationships field). I want to sort through each list of children and only display certain results. I've tried using

foreach($areas['list'] AS $item) {

    echo CobaltApi::renderField($item, '25', 'list'); //25 is field ID of child field.

}

This shows me all of the children, but this doesn't allow me to filter the results.

I hope this is clear, any help is very appreciated.

Last Modified: 02 Mar 2014


Sergey
Total posts: 13,748
04 Dec 2013 01:38

renderField return HTML only.

In your first example that is strange. $ids must be 12th parameter not 4th.

What you can do is to query child section through API.

// Get list of IDs of parents

$db->setQuery("SELECT id FROM _js_res_record WHERE section_id = 4 AND ....");

$ids = $db->loadColumn();

$list = $api->records($section_id, ..., ..., ..., $ids);

foreach($list['list'] AS $item) {

echo $item->fields_by_id[25]->result;

}


Sergey
Total posts: 13,748
05 Dec 2013 00:38

I am not sure it is 25. it have to be ID of the field in child that you want. Try this

var_dump(array_keys($item->fields_by_id));

And see what IDs you have available.


Guest
05 Dec 2013 09:51

The "ID of the field in child that I want"? I am not following. I would like to look at the list of children that come back and only show the children that are part of 'Category A'. All of my children are in Section 1. Section 1 has a relationship field that corresponds to Section 4. There can be multiple relationships.

25 is the ID of the child field in Section 4.

I have the first part working, where I only show specfic IDs of Section 4. Now from these IDs I need to show specific child records.

When I do

foreach($areas['list'] AS $item) {

    var_dump(array_keys($item->fields_by_id));}

I get

array(0) { } 

So it looks like child fields do not show up in fields_by_id?


Sergey
Total posts: 13,748
06 Dec 2013 01:27

Look what I propose that you select records of different type and different section than type where field 25 is. It cannot be there. There have to be list of fields of type that is selected as connected in field 25.

Powered by Cobalt