Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Global Set called "Settings" (handle = 'settings'); Within that I have a text field called "Address" (handle = 'address').

I have a function in my Plugin and I'd like to get the Address data.

In the front-end I would write this:

{{ settings.address }}

How can I get the same information in my plugin with PHP?

I've got as far as this:

$address = craft()->elements->getCriteria(ElementType::GlobalSet);

When I var_dump this array, I can see the address string. But I can't figure out how to filter down to the address correctly.


share|improve this question
up vote 12 down vote accepted

You can use the GlobalsService service available with craft()->globals like so:

// Get the settings global set
$settings = craft()->globals->getSetByHandle('settings');

// Access the address field

Or you could use ElementCriteria as you suggested:

// Get the GlobalSet element critera
$criteria = craft()->elements->getCriteria(ElementType::GlobalSet);
// Set the handle you want
$criteria->handle = 'settings';
// Find the settings set
$settings = $criteria->first();

// Access the address field

You can access all fields on the $settings variable using this synthax.


share|improve this answer
Thanks for the quick and concise answer Mario. They both worked like a charm. I think I'll use use your first suggestion though... as it's more tidy and does exactly what I need. – Mark Notton Aug 5 '14 at 13:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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