If you have an attribute type in a package you need to do a little additional work in the install routine to get it registered fully with the system.

<br></br>
/* We install the attribute... */<br></br>
Loader::model('attribute/type');<br></br>
$at = AttributeType::add('country', 'Country', $pkg);<br></br>
/* then we associate with collections and users. */<br></br>
Loader::model('attribute/category');<br></br>
foreach (array('collection', 'user') as $c) {<br></br>
    $cat = AttributeKeyCategory::getByHandle($c);<br></br>
    $cat->associateAttributeKeyType($at);<br></br>
}```

If you also want the attribute associated with files then add ‘file’ to the collections above.

Following the above the attribute will be available in the Dashboard / Page & Themes / Attributes page to be added as a page attribute.

If you want to add a page attribute at the same time as the attribute then the following code can be used (assuming it follows on directly from the above)




Loader::model('collection_attributes');


$data = array('akHandle' => 'my_attribute,


'akName' => 'My Attribute',


'akIsSearchable' => true,


'akIsSearchableIndexed' => true);


$att = CollectionAttributeKey::add($at, $data, $pkg);

```

Of course, you may also want to add this attribute you have just created to an attribute set, so you can also do this (once again assuming continuation of code from the above)

<br></br>
Loader::model('attribute/set');<br></br>
$aset = AttributeSet::getByHandle('navigation');<br></br>
$att->setAttributeSet($aset);<br></br>```

Hopefully this can help others avoid spending the time it took me to figure this out 🙂