Help topics

Look up and search entries

Make a field unique to refuse duplicates and look up one entry by its value, or turn on search to find entries by their words.

Before you start

  • You need the administrator role to change a model.

Make a field unique

Only fields that can be filtered can be unique, and lists cannot be unique. A text field can be filtered only when it is not multiline and its maximum length is 256 or less.

  1. Select Models.
  2. Open the model.
  3. Open the field, for example slug.
  4. Turn on Unique. The Unique switch appears only for fields that can be filtered.
  5. Select Save changes.

Result: Saving a second entry with the same value fails with the message "another article already has this slug".

Look up an entry by its unique value

Send a GET request to the unique rule. The rule has the name of the field, and you send the value as a query parameter with the same name.

curl "https://example.com/wp-json/morphic/v1/by/article/slug?slug=hello-world"

Result: The response is the one entry with that slug.

If the field is not unique, the response is an error with the message "article has no unique rule slug". If you leave out the value, the response says getBy needs every field of slug.

Make a rule unique across fields or within a parent

  1. Open the model.
  2. Select the Filters & search tab.
  3. In the Unique values section, select Add rule.
  4. Choose the fields that must be unique together.
  5. For the scope, select across the site or within the same parent.

Result: With within the same parent, two entries can share the value when they have different parents.

Search the words in text fields

Searchable applies only to text and rich text fields that are not secret.

  1. Open a text or rich text field.
  2. Turn on Searchable.
  3. Select Save changes.
  4. Send a GET request with the words in q.
curl "https://example.com/wp-json/morphic/v1/search/article?q=headless+wordpress&limit=10"

Result: The response lists the matching entries. Each item has a score value.

The q parameter is required. Without it, the response says that search needs q. Add field to search only one field. If a field has no search index, the response says <model> has no fulltext index on <field>.