Skip to main content

Function Signature

Fetches blog posts from the WordPress CMS API endpoint. This function retrieves posts with embedded media and taxonomy data, then transforms them into the application’s BlogPost format.

Parameters

number
default:"10"
The number of blog posts to retrieve per request. Optional parameter that defaults to 10 posts.

Return Type

Promise<BlogPost[]>
Returns a Promise that resolves to an array of blog post objects.

Behavior

  • Makes a GET request to the WordPress REST API /posts endpoint
  • Includes _embed parameter to fetch related media and taxonomy data
  • Strips HTML tags from title and excerpt fields
  • Formats dates using Spanish locale (es-ES)
  • Provides fallback placeholder image if featured media is not available
  • Throws an error if the API request fails

Error Handling

Throws an error with the format:

Usage Example

Basic Usage (Default 10 Posts)

Custom Number of Posts

With Error Handling

API Endpoint

The function connects to: