Support Log in

15. REST API Overview

Developer Guide
Prefer video? Watch the Lang Forge tutorials 9 short guides covering every feature Watch

All endpoints require authentication (user must have edit_posts capability unless otherwise noted). The namespace is langforge/v1. Authentication can be via cookie nonce (X-WP-Nonce header), application passwords (Basic Auth), or any WordPress authentication plugin.

Authentication Methods

bash
# Method 1: Cookie nonce (for JavaScript in the admin)
curl -s "https://example.com/wp-json/langforge/v1/languages" 
  -H "X-WP-Nonce: abc123def456"

# Method 2: Application password (for external scripts)
curl -s "https://example.com/wp-json/langforge/v1/languages" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX"

# Method 3: Basic Auth plugin (for development)
curl -s "https://example.com/wp-json/langforge/v1/languages" 
  -H "Authorization: Basic $(echo -n 'admin:password' | base64)"

Dynamic REST Fields on Posts

Lang Forge registers two additional fields on all post type REST responses that have show_in_rest enabled:

bash
# Standard WP REST API post request
curl -s "https://example.com/wp-json/wp/v2/posts/42" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX"
Additional fields in response:
json
{
    "id": 42,
    "title": { "rendered": "About Us" },
    "lf_language": "ru",
    "lf_translations": {
        "ru": 42,
        "en": 99,
        "de": 155
    }
}

The lf_language field is writable via PUT/POST:

bash
# Set the language of a post via REST API
curl -s -X POST "https://example.com/wp-json/wp/v2/posts/42" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX" 
  -H "Content-Type: application/json" 
  -d '{ "lf_language": "en" }'

Filtering Posts by Language via REST API

bash
# Get all English posts
curl -s "https://example.com/wp-json/wp/v2/posts?meta_key=_lf_language&meta_value=en" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX"

# Get all English pages
curl -s "https://example.com/wp-json/wp/v2/pages?meta_key=_lf_language&meta_value=en" 
  -u "admin:XXXX XXXX XXXX XXXX XXXX XXXX"

Forge AI Assistant Online

Hi! I'm the Lang Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs