https://github.com/mrwweb/acf-helper-functions
A powerful set of functions for outputting common markup patterns with Advanced Custom Fields Plugin for WordPress.
https://github.com/mrwweb/acf-helper-functions
Last synced: 5 months ago
JSON representation
A powerful set of functions for outputting common markup patterns with Advanced Custom Fields Plugin for WordPress.
- Host: GitHub
- URL: https://github.com/mrwweb/acf-helper-functions
- Owner: mrwweb
- License: gpl-2.0
- Created: 2013-11-08T19:03:27.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-03-24T22:16:24.000Z (about 11 years ago)
- Last Synced: 2024-12-16T13:18:36.748Z (5 months ago)
- Language: PHP
- Size: 141 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ACF Output Helper Functions
A powerful set of functions for outputting common markup patterns with [Advanced Custom Fields Plugin](http://wordpress.org/plugins/advanced-custom-fields/) for WordPress.
Formerly [a gist](https://gist.github.com/mrwweb/5768363). Intial [ACF Forums discussion](http://old.support.advancedcustomfields.com/discussion/comment/19680).
## OVERVIEW
Two simple functions: `get_acf_field()` and `the_acf_field()`, the latter of which is just a simple wrapper function.
The functions let you replace this:
```php
My Field: ' . $my_field . '';
}
?>
```With this:
```php
'My Field', 'itemprop' => 'name' ); ?>
```## WHY?
It gets annoying to repeat so much code to output a simple ACF field. You have to test if the field is there, add a label, add schema.org markup, etc. This tries to help take care of some of the most common and repetitive output patterns.
## ARGUMENTS
The `$args` parameter accepts an `array` or query_string-style format.
Array Format:
`array( 'type' => 'text', 'label' => 'a label' );`
Query String Format:
`type=text&label=a label`
### Argument Documentation`type` Valid types:
* `text` **(default)**
* `image` (field store ID)
* `email` (outputs as `mailto:` link, uses `link_label` arg if provided)
* `url` (won't display field if equal to 'http://')
* `link` (same as URL, but output as link and with optional `link_label` arg)
* `date` (must be stored as stored as recommended yymmdd format)
* `post_list` (a delimited list of posts selected with a relationship field)
* `term` (a single term from a taxonomy, assumes ID is stored)
* `term_link` (link to a term archive from a taxonomy, assumed ID is stored)
* `custom` (use the `return_get_acf_field` filter to add more types)`label` Puts label before field output. Label wrapped in a ``
`link_label` Anchor text for `link` or `email` field types.
`image_size` only used with `'type' => 'image'`
`image_class` only used with `'type' => 'image'`
`itemprop` Wraps field value in `` with the specified schema.org property
`date_format` PHP date format to return. *only used with `'type' => 'date'`*
`before` HTML before the field out
`after` HTML after the field output
`sub_field` Set to `true` if using `get_acf_field` in a repeater or flexible field
`list_sep` Delimiter string for `post_list` type
`list_links` Should the `post_list` items link to posts? Default: `true`
`list_type` Format that relationship field uses to store data. Default: 'objects'
`taxonomy` Taxonomy containing the term. Requried for `term` field.
## TO-DOS
* Add more types (suggestions welcome)
* Add sanitization
* Complete support for `itemprop`## CHANGELOG
### 13 Jun 2013
* Added changelog
* [new] filter to add new types: `return_get_acf_field`
* (thanks @wells5609: https://gist.github.com/wells5609/5786376)
* [new] filter for label class: `get_acf_field_label_class`### 28 Jun 2013
* [new] post_list type
* [new] date type
* [new] `sub_field` argument for use in `while( has_sub_field() ) ...`
### 11 Jul 2013
* [new] term and term_link types added for taxonomy fields for a single term### 9 Nov 2013
* [improvement] More consistent, cleaner handling of `itemprop` arg. (Shifting to use of `sprintf`.)
* [new] `link_label` argument for `email` and `link` field types.