REST API

  • JNext lesson
  • KPrevious lesson
  • FSearch lessons
  • EscClear search

Namespace: dmyip/v1

The dmyip/v1 REST API exposes the same date rendering as the shortcodes, publicly and read-only, so headless frontends and external tools can fetch the exact values the plugin would render in WordPress.

All endpoints are public (no authentication required). Available when the modern loading path is active (requires vendor/autoload.php).


GET /wp-json/dmyip/v1/dates

Returns all date types organized by category.

Response:

{
  "year": {
    "current": "2026",
    "next": "2027",
    "previous": "2025"
  },
  "month": {
    "current": "February",
    "current_short": "Feb",
    "next": "March",
    "previous": "January",
    "number": "2"
  },
  "day": {
    "current": "18",
    "next": "19",
    "previous": "17",
    "weekday": "Tuesday",
    "weekday_short": "Tue"
  },
  "combined": {
    "date": "February 18, 2026",
    "monthyear": "February 2026",
    "next_monthyear": "March 2026",
    "prev_monthyear": "January 2026"
  },
  "events": {
    "blackfriday": "November 28",
    "cybermonday": "December 1"
  },
  "season": {
    "north": "Winter",
    "south": "Summer"
  },
  "timezone": "America/New_York",
  "timestamp": 1771372800,
  "gmt_offset": -5,
  "date_format": "F j, Y",
  "time_format": "g:i a"
}

GET /wp-json/dmyip/v1/date/{type}

Returns a single date value.

Path parameter:

  • type (required) – Any supported date type

Query parameters:

  • offset (int, optional) – Year offset
  • date (string, optional) – Target date for countdown/age types (YYYY-MM-DD)

Supported types: year, nyear, pyear, month, mon, nmonth, pmonth, date, monthyear, dt, weekday, wd, blackfriday, cybermonday, datepublished, datemodified, daysuntil, dayssince, age, season

Examples:

GET /wp-json/dmyip/v1/date/year
→ {"type": "year", "value": "2026"}

GET /wp-json/dmyip/v1/date/year?offset=5
→ {"type": "year", "value": "2031"}

GET /wp-json/dmyip/v1/date/month
→ {"type": "month", "value": "February"}

GET /wp-json/dmyip/v1/date/daysuntil?date=2026-12-25
→ {"type": "daysuntil", "value": "310"}

GET /wp-json/dmyip/v1/date/age?date=1990-05-15
→ {"type": "age", "value": "35"}

GET /wp-json/dmyip/v1/date/season
→ {"type": "season", "value": "Winter"}

GET /wp-json/dmyip/v1/shortcodes

Returns all shortcodes categorized with descriptions and examples.

Response structure:

{
  "year": [
    {"shortcode": "[year]", "description": "Current year", "example": "2026"},
    {"shortcode": "[nyear]", "description": "Next year", "example": "2027"}
  ],
  "month": [
    {"shortcode": "[month]", "description": "Current month", "example": "February"}
  ],
  "day": [...],
  "combined": [...],
  "events": [...],
  "countdown": [...],
  "season": [...],
  "post_dates": [...]
}

Usage from JavaScript

// Fetch all dates
const response = await fetch('/wp-json/dmyip/v1/dates');
const dates = await response.json();
console.log(dates.year.current); // "2026"
console.log(dates.month.current); // "February"
console.log(dates.season.north); // "Winter"

// Fetch a specific date type
const age = await fetch('/wp-json/dmyip/v1/date/age?date=1990-05-15');
const data = await age.json();
console.log(data.value); // "35"

// Fetch with year offset
const futureYear = await fetch('/wp-json/dmyip/v1/date/year?offset=10');
const result = await futureYear.json();
console.log(result.value); // "2036"

Usage from cURL

# All dates
curl https://example.com/wp-json/dmyip/v1/dates

# Single date
curl https://example.com/wp-json/dmyip/v1/date/year

# Age calculation
curl "https://example.com/wp-json/dmyip/v1/date/age?date=1990-05-15"

# Days until event
curl "https://example.com/wp-json/dmyip/v1/date/daysuntil?date=2026-12-25"

# List all shortcodes
curl https://example.com/wp-json/dmyip/v1/shortcodes

Quick answers to common questions:

Why are the endpoints public?

They return computed dates, not site data, so there’s nothing to protect: the same values any visitor sees rendered in your content. Public access is what makes headless and JavaScript use cases work without auth plumbing.

When would I actually use the REST API?

Headless WordPress builds that need consistent date rendering with the backend, external dashboards displaying countdowns, and integration tests verifying shortcode output. For PHP contexts, the shortcodes and functions are simpler.