Skip to content

Helpers

Brian McCoy edited this page Feb 23, 2018 · 7 revisions

Alloy Core comes with a few functions available to aid in your development.

_log( $array );

A wrapper for error_log() that will print strings, arrays or objects to the system error log.

core_get_fields( $key='', $prefix='', $fields=array(), $single=false )

Retrieves a group of custom fields. It's basically a wrapper for ACF's get_field function. It takes $fields and loops through them, calls get_field and returns the results as an array. If single is set to true then it doesn't return an array it just returns the value of the single field defined.

Example:

$fields = core_get_fields( $this->obj_id, 'hero_', array(
	'heading',
	'sub_heading',
	'description',
	'background_image'
) );```

`$key` is the object you are retrieving fields from. Some examples would be the page ID, or if it's an option "option". 
`$prefix` is good for if you have a lot of fields that belong to the same section. In the example above we are loading the fields for a hero section and every field is prefixed with `hero_` like `hero_heading`.

In this example you can access data like `$fields['heading']`

Another example:

```php
$social = core_get_fields( 'option', '', array(
	'facebook_url'
), true );

The above example would return the value for Facebook URL if you echoed out $social.

Clone this wiki locally