Help topics

Create a view with live counts and sums

A view is a saved list of entries, with fields copied from related entries and counts and sums kept for each group. Use one when a screen or API needs the same joined list again and again.

Before you start

  • Morphic Pro is required.
  • You need the WordPress Administrator role, because views are saved with the model.
  • The model has the entries and relations you want to join.

Add a view

  1. Go to Morphic > Models and open the model.
  2. Select the Views tab.
  3. Select Add view. A model can have up to 8 views.
  4. In the view's name field, enter a name.

Set the rows and columns

  1. In Group by, select the fields. Morphic keeps one row for each group, such as one row per author. Leave it empty for one list of everything. You can select up to 4 fields.
  2. In Sort, select the fields. You can select up to 4 fields.
  3. Optional: Select Toggle direction next to a field to sort it in descending order.
  4. In Only include when, add the conditions that entries must meet.
  5. In Columns, add the fields to copy into each row. You can copy fields of a linked entry one step away. You can add up to 16 columns.

Add counts and sums

  1. Optional: Turn on Keep a count per group to keep a count for each group.
  2. Optional: In Keep sums of, select number fields to sum. You can select up to 4.
  3. Select Save changes.

Result: the view lists one row for each group. Morphic updates the rows when an entry is saved. Select Open on the view to see its entries.

Read a view through the API

The view reads at lens/<model>/<view> on the REST API address shown on the API & integration screen. Pass the group values with key[], and limit the rows with limit.

curl "<REST address>lens/article/by_author?key[]=aut_…&limit=20"

Add /count to the address to read the counts and sums for the same group:

curl "<REST address>lens/article/by_author/count?key[]=aut_…"

Delete a view

  1. Select the trash icon labelled Delete view on the view.
  2. In the dialog titled Delete view followed by the view name, select Delete.

Morphic removes the stored rows in the background. Your entries are not affected.