I would like to get all the fields (with their handles and values) for a given global set.

For example : My set is called 'labels'. I know I can get the set by using :

$criteria = craft()->elements->getCriteria(ElementType::GlobalSet);
$criteria->handle = 'labels';
$labels = $criteria->first();

Or with :

$labels = craft()->globals->getSetByHandle('labels');

Then I can get a specific data with


But how can I get all the data/fields in the set ? I would like to have an array or an object with all my labels (in my controller I return the value using returnJson).

Thanks for your help !


Have a look at the answer given here to someone trying to solve this in the template. With a plugin you'd probably do it like so:

public function getFieldsByEntry($entryModel)
    $fields = array();
    $fieldLayoutFields = $entryModel->getFieldLayout()->getFields();
    foreach ($fieldLayoutFields as $fieldLayoutField)
        $fields[] = craft()->fields->getFieldById($fieldLayoutField->fieldId);
    return $fields;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.