Shortcode and block reference
Morphic provides three shortcodes and a block binding source. Add a shortcode to the content of any WordPress page or post, and use the block binding source in the block editor.
[morphic_list]
Shows the entries of one model as a list, table or cards.
Example: [morphic_list model="book" layout="table" fields="author,price" limit="5"]
| Attribute | What it does | Options | Default |
|---|---|---|---|
| model | The model whose entries are listed. Nothing is shown when this is empty or the model is not registered. | Model name | (empty) |
| where | Filters the entries. Separate conditions with commas. Use field:value for an exact match, and >, >=, < or <= for a range. Only one range field is allowed. | field:value, field>=value, field<value and the other range forms | (empty, no filter) |
| order | The field to sort by. Put a minus sign before the field name to sort in descending order. | Field name, or - + field name | (empty) |
| limit | The number of entries. A value below 1 is shown as 1, and a value above 100 as 100. | 1 to 100 | 10 |
| layout | How the entries are shown. Any other value shows cards. | cards, list, table | cards |
| fields | The fields to show, in the order given, separated by commas. The list layout ignores this attribute. | Field names | (empty) |
| lang | The language of the entries. When empty, no language is passed to the query. | Language code | (empty) |
- With no where, and order empty or
-created, the entries come back in reverse order. - Cards show the first three fields of the model when fields is empty. The title field is not repeated, so fewer than three may show. The table shows all fields.
[morphic_entry]
Shows one entry. Without content between the tags, it shows the entry title as a heading and the other fields with their labels.
Example: [morphic_entry model="book" unique="title" slug="Maps of Forgotten Towns" fields="author,price"]
| Attribute | What it does | Options | Default |
|---|---|---|---|
| model | The model of the entry. Nothing is shown when this is empty or the model is not registered. | Model name | (empty) |
| id | The ID of the entry. When this is set, unique and slug are ignored. | Entry ID | (empty) |
| slug | The value to match in the field named by unique. Used only when id is empty. | Value | (empty) |
| unique | The field that slug is matched against. | Field name | slug |
| fields | The fields to show, in the order given, separated by commas. When empty, all fields are shown except the title field. | Field names | (empty) |
| lang | The language of the entry. Used only together with id. | Language code | (empty) |
- Content between
[morphic_entry]and[/morphic_entry]is shown with the entry as context, so[morphic_field]inside it shows values of this entry. The content is filtered with the same rules as WordPress post content, plus iframe tags.
[morphic_field]
Shows one value of an entry.
Example: [morphic_field name="author"]
| Attribute | What it does | Options | Default |
|---|---|---|---|
| name | The field to show. title shows the entry title, and url shows the public URL of the entry. Names that are not fields of the model show nothing. | Field name, title, url | (empty) |
| id | The entry to use when there is no entry in context and no current Morphic page. | Entry ID | (empty) |
| model | The model of id. Used only together with id. | Model name | (empty) |
- The entry in context is the entry of the nearest enclosing
[morphic_entry]. When there is none, the current Morphic page is used. [morphic_field]shows nothing when there is no entry.
Values shown by the shortcodes and block bindings
- A Yes or No field shows Yes or No.
- Secret and hidden fields never show, in any shortcode or block binding. Empty values show nothing.
Block bindings
- Morphic field is the name of the block binding source (
morphic/field) in the block editor. Set the binding argumentkeyto a field name. The source shows nothing when the post has no entry, the key is empty, or the model has no field with that name. - Post Author Name (
core/post-author-name) with no text of its own shows the names in the entry's byline, up to three, separated by commas. The byline is the relation field configured as byline. When none is configured, Morphic uses the first relation field namedauthor,authors,writer,bylineorcreatedBy. - Post Terms (
core/post-terms) with no text of its own shows the linked entries for the taxonomy in itstermsetting. Onlycategoryandpost_tagare supported. The separator is,unless the block sets separator.
Labels and fallbacks
| Text | Where it appears |
|---|---|
| Untitled | The title of an entry that has no title value. |
| Title | The first column heading of a table when the model has no title field. |
| Morphic field | The name of the block binding source. |
| Yes and No | The values of Yes or No fields. |
| Nothing here yet. | A list with no entries. |
[morphic_field name="url"] shows nothing when the entry has no URL. No label is shown in that case.
Errors and visitor output
- A list with a where or order that no index answers shows this text to users with the
manage_optionscapability. Other visitors see nothing:No filter of book matches this list. Turn on "Filter by this field" for: author. The model name comes from model, and the field names come from where. - A lookup error in any shortcode shows its message to users with the
manage_optionscapability, in a paragraph with the classmorphic-error. Other visitors see no output. See Error codes and messages reference for the messages.
Secret and hidden fields
Secret and hidden fields never show in a shortcode or a block binding. In a table, the column heading still shows and the cell stays empty.