Fetching Data

Static Fetch

Use {{ fetch.static }} when JSON data changes rarely and can be cached persistently with the theme.

Basic Shape#

php
{{ fetch.static "https://api.example.com/movie?id=123" as movie }}  <article>    <h2>{{ movie.Title }}</h2>    <p>{{ movie.Year }}</p>  </article>{{ /fetch.static }}

{{ fetch.static }} works like {{ fetch }} in your template. It supports path, as, and {{ else }}.

The difference is caching. Static fetch is meant for data that should not need a fresh API request on every page render.

When To Use It#

Use static fetch for data such as:

  • movie details
  • directory entries
  • reference data
  • API-backed content that changes rarely

Use normal {{ fetch }} when the API data should be checked regularly at runtime.

Build And Runtime Cache#

Literal static fetch URLs can be warmed during a theme build:

php
{{ fetch.static "https://api.example.com/settings" as settings }}  <p>{{ settings.title }}</p>{{ /fetch.static }}

Dynamic static fetch URLs are cached when WordPress renders them:

php
{{ fetch.static "https://api.example.com/movie?t={{ slug }}" as movie }}  <h2>{{ movie.Title }}</h2>{{ /fetch.static }}

Published themes keep the static fetch cache with the theme when possible.

Choose Fetch Or Static Fetch#

TagUse it when
{{ fetch }}The data should be checked at runtime and cached briefly.
{{ fetch.static }}The data changes rarely and should be cached persistently.