Answers.Body: <p>If you want to get all values from a global set without having to specify each field handle you can do something like this:</p>
  
  <pre><code>$set = craft()-&gt;globals-&gt;getSetByHandle('globalHandleHere');
  $fieldLayoutFields = $set-&gt;getFieldLayout()-&gt;getFields();
  
  foreach ($fieldLayoutFields as $fieldLayoutField) {
      $field = craft()-&gt;fields-&gt;getFieldById($fieldLayoutField-&gt;fieldId);   
      $value = $set-&gt;getContent()[$field-&gt;handle];
  
      // Do whatever with $value here.
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-06T09:58:09.833Z
Answers.Text: Thanks @Ragnarsson for adding a good answer to an older post. I can see this being useful for something I'm working on right now oddly enough. Thanks again!
Answers.UserDisplayName: Mark Notton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-06T11:25:22.237Z
Answers.Text: Glad I could help Mark. Remember that depending on the fieldtypes in the global you might have to extend this code. The code above would return null for assets for example. You might want to switch over the $field->type and write code that can handle all expected types.
Answers.UserDisplayName: Ragnarsson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-06T09:40:06.413Z
Answers.LastActivityDate: 2016-09-06T17:42:42.137Z
Answers.LastEditDate: 2016-09-06T17:42:42.137Z
Answers.UserDisplayName: Ragnarsson
Answers.Body: <p>You can use the GlobalsService service available with <code>craft()-&gt;globals</code> like so:</p>
  
  <pre class="lang-php prettyprint-override"><code>// Get the settings global set
  $settings = craft()-&gt;globals-&gt;getSetByHandle('settings');
  
  // Access the address field
  var_dump($settings-&gt;address)
  </code></pre>
  
  <p>Or you could use ElementCriteria as you suggested:</p>
  
  <pre class="lang-php prettyprint-override"><code>// Get the GlobalSet element critera
  $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::GlobalSet);
  // Set the handle you want
  $criteria-&gt;handle = 'settings';
  // Find the settings set
  $settings = $criteria-&gt;first();
  
  // Access the address field
  var_dump($settings-&gt;address)
  </code></pre>
  
  <p>You can access all fields on the <code>$settings</code> variable using this synthax.</p>
  
  <p>Mario</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-05T13:08:43.043Z
Answers.Text: 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.
Answers.UserDisplayName: Mark Notton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-05T12:30:00.080Z
Answers.LastActivityDate: 2014-08-05T12:37:55.117Z
Answers.LastEditDate: 2014-08-05T12:37:55.117Z
Answers.UserDisplayName: Mario
Body: <p>I have a Global Set called "Settings" (handle = 'settings'); Within that I have a text field called "Address" (handle = 'address'). </p>
  
  <p>I have a function in my Plugin and I'd like to get the Address data. </p>
  
  <p>In the front-end I would write this: </p>
  
  
  
  <pre><code>{{ settings.address }}
  </code></pre>
  
  <p>How can I get the same information in my plugin with PHP? </p>
  
  <p>I've got as far as this: </p>
  
  <pre class="lang-php prettyprint-override"><code>$address = craft()-&gt;elements-&gt;getCriteria(ElementType::GlobalSet);
  </code></pre>
  
  <p>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. </p>
  
  <p>Thanks</p>
  
Tags: <plugin-development><globals>
Title: How to get data from a Global Set in a plugin?
ThreadText: # How to get data from a Global Set in a plugin?
  
  (Asked by: username_0 on 2014-08-05)
  
  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:
  
  ```php
  $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.
  
  Thanks
  
  **Tags:** plugin-development, globals
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-08-05. Score: 24 | Accepted answer
  
  You can use the GlobalsService service available with `craft()->globals` like so:
  
  ```php
  // Get the settings global set
  $settings = craft()->globals->getSetByHandle('settings');
  
  // Access the address field
  var_dump($settings->address)
  
  ```
  
  Or you could use ElementCriteria as you suggested:
  
  ```php
  // 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
  var_dump($settings->address)
  
  ```
  
  You can access all fields on the `$settings` variable using this synthax.
  
  username_2
  
  > **Comments:**
  > **username_0**: Thanks for the quick and concise answer username_2. 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.  
  
  ---
  
  ### Answer by username_1 on 2016-09-06. Score: 3
  
  If you want to get all values from a global set without having to specify each field handle you can do something like this:
  
  ```
  $set = craft()->globals->getSetByHandle('globalHandleHere');
  $fieldLayoutFields = $set->getFieldLayout()->getFields();
  
  foreach ($fieldLayoutFields as $fieldLayoutField) {
      $field = craft()->fields->getFieldById($fieldLayoutField->fieldId);   
      $value = $set->getContent()[$field->handle];
  
      // Do whatever with $value here.
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks @username_1 for adding a good answer to an older post. I can see this being useful for something I'm working on right now oddly enough. Thanks again!  
  > **username_1**: Glad I could help Mark. Remember that depending on the fieldtypes in the global you might have to extend this code. The code above would return null for assets for example. You might want to switch over the $field->type and write code that can handle all expected types.  
  
  ---
  
  