The PHP API
The PHP API
The few functions that read, print, find and save your fields from your theme.
ugly_get( 'field' ); // the value, ready to use
ugly_show( 'field' ); // prints it, safe to print
ugly_rows( 'field' ); // the rows of a repeater or flexible content, to loop over
ugly_update( 'field', $value ); // saves it, cleaned like what an editor types
ugly_delete( 'field' ); // deletes it
ugly_find( 'recipe', [ ... ] ); // finds posts by their fields[ugly-fields field="field"] // the same as ugly_show(), inside contentIn this chapter
Reading values 4
- ugly_get() or ugly_show()? They are the same pair as get_field() and the_field() of ACF.
- Where the value comes from (the second argument) Every function takes, as its second argument, where to read from. Without it, it reads from the page or post being shown.
- What each type gives back The PHP API
- Rows: repeater, group and flexible content A repeater gives a list of rows. Loop over it with ugly_rows( 'name' ): the list is empty (and never gives a warning) when the field is not there for that post.
Writing and finding 3
- Writing and deleting What you write goes through the same cleaning as what the editor writes. A number out of range is cut. A badly typed color is dropped. A value that does not belong is not saved.
- Finding posts by their fields: ugly_find() No meta_query. You say what the fields must be.
- Two-way relations In a field that points at posts (Relationship [PRO] or Page or post), turn on Show it on the other side too and write what the other side calls it ("Friends of", "Books").
More 4
- The shortcode It prints what ugly_show() prints, so it is safe. Use it to put a value inside the content of a page. You can switch it off in Settings → Advanced.
- Inside a block In the render file of a block, ugly_get() and ugly_show() read the fields of that block. $block holds them as one row. More in Blocks.
- Other functions The PHP API
- Things to remember The PHP API
No page matches. Try another word.
Where to go next
| You want to… | Read |
|---|---|
| Look up one function | Reference: functions |
| Copy a working recipe | Cookbook |
| Write safe, fast templates | Best practices |
| Understand the safety model | Security |
Did this article answer your question?
Thank you. It helps us make the documentation better. Need more help?