Function Signature
BlogPost format.
Parameters
The number of blog posts to retrieve per request. Optional parameter that defaults to 10 posts.
Return Type
Returns a Promise that resolves to an array of blog post objects.
Behavior
- Makes a GET request to the WordPress REST API
/postsendpoint - Includes
_embedparameter 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:Related
- fetchWPPageBySlug - Fetch individual WordPress pages by slug
- BlogPost Type - Type definition for blog post objects