Transforms
October 18th, 2014
Available in version 2.8. This functionality is an ALPHA version.
Transforms are functions applied to data to change it in some way in a short code. Short code processing proceeds like this:
- The database is queried
- “unbuffered” and “random” are applied
- “tfilter” or “tsearch” filters query results
- “torderby” orders the results
- “tlimit” limits the number of rows query
- “trans” is applied for each listed transform in order
- Each transform can change values of fields, add or remove fields
- The results of each transform is the input for the next
- “filter” or “search” is applied on the last transform results
- field names should refer to those in the transform results
- “limit” is applied
- “orderby” is applied
- “show” and “hide” and short code-specific options are applied
Notes:
- tfilter, tsearch, torderby, and tlimit work like filter, search, orderby and limit respectively
- tfilter, tsearch, torderby, and tlimit happen before trans transforms are applied whereas filter, search, orderby and limit are applied after
- tfilter, tsearch, torderby, and tlimit are ignored if there is no trans
Transform Examples
Transform Functions are
- PHP functions used to change a single field such as trans=”name=strtoupper(name)” would re-assign the “name” field to be upper-cased. You could also assign a new field trans=”upper-name=strtoupper(name)”
- Most PHP string-related functions (like “strtoupper”) can be used
- You can create your own function and use it
- PHP functions used to change the any part or all of the data set such as trans=”myfunction” where you define function myfunction($data) {}. $data is an associated array of file => value. The functions should return an associative array of the results.
- PHP classes to change change the any part or all of the data set such trans=”NaturalSortByField(name)”.
Transforms can be changed together using &&. Example:
- trans=”name=strtoupper(name)&&NaturalSortByField(name)“
See more on Transform Functions and Transform Classes.