Last modified by MammaMia - 7 years ago
334 Views
3 min read

Displaying and using custom fields in entity view layouts

WordPress custom fields functionality provides a quick way to allow users to extend the content with key/value pairs also known as meta data. Custom fields store arbitrary extra information about entities. This feature can be enabled by selecting "Custom fields" checkbox under entity edit screen "Options" tab, "Supports" check box list in WP App Studio.

Custom fields differ from entity attributes in the way that they are defined in your app designs. Attributes are essential part of app designs and fully controlled by app designers. Custom fields are arbitrary user entered information hence can not be known in the design time. Users may create different custom fields per entity record.

Creating custom fields

Custom fields can be created in the entity edit screen scrolling down to the area titled Custom Fields. In the area, users can enter key/value pairs for each field they want to store.

The key is the name of the field. The value is the information that is associated with the key. For example, user can enter "source" as key and  "the source url" as value to store the source of the information provided in the content.

Custom fields can be updated or deleted by users anytime provided that they have access to the edit screen of entity.

Users may use the same custom field "keys" to enter multiple "values". In this case WPAS concatenates each value of the key separated by a single space character. Users can create as many custom fields as they can.

WordPress displays previously defined custom fields as dropdown list to allow users to select from the list.

WPAS only displays custom fields created within the entity edit screen. If you have other WordPress plugins supporting custom fields, the fields created by them are excluded in the dropdown since they are not related to the entity record. This feature also protects data integrity of your app by eliminating the risk of users selecting non-entity related keys from the list.

Displaying custom fields

Custom fields can be displayed in view, widget and relationship layouts using the following tag function:

!#custom-attr['Header','Begin Html','Middle Html','End Html','Footer']#

  • Header: The header section of the HTML code which wraps all custom fields blocks(loop)
  • Begin HTML: The HTML code before the label(key)
  • Middle HTML: The HTML code after the label(key) and before the value
  • End HTML: The HTML code after the value
  • Footer: The footer section of the HTML code which wraps all custom fields blocks(loop)

The following shows a usage scenario where WPAS loops over the custom fields of an entity to display key/value pairs in the format defined in the tag function:

!#custom-attr['<div class="grid grid-pad cust-field"><span><strong>',': </strong></span><span>','</span></div>']#

Please note that you must use double quotes in your HTML to display the code correctly. If you do not use header or footer parameters, include comma and empty single quotes for them. For example, ,''

Using custom fields in forms

Custom fields can be displayed in submit or search forms like any other entity attribute. Currently, all custom fields are displayed as textbox.

To use custom fields in your forms, go to the generated plugin's settings menu and select "Forms" tab as you would normally do to include or exclude custom fields from from layouts. You can also make custom fields required or optional depending of your need.

Including a custom field in the form layout is a quick way of standardizing the field for all records of the corresponding entity.

Custom fields are automatically added to every form layout attached to the entity which supports custom fields in generation time. However, they must be enabled per field basis by WordPress administrator users to be displayed in form layouts.

Conclusion

WordPress custom fields is a nice to have feature if you'd like to offer users the ability to create arbitrary information. Custom fields differ from entity attributes in the way they are defined in the design time. Users have full control on the information included in the custom fields so designers should think about the issues such as data integrity, database growth etc. before enabling this feature in app designs.

Related Embeds
Previous Next
Related Panels
Related Articles
Related Documents
Previous Next
Was this information helpful?