MCPcopy Create free account
hub / github.com/9d8dev/next-wp / wordpressFetch

Function wordpressFetch

lib/wordpress.ts:51–76  ·  view source on GitHub ↗
(
  path: string,
  query?: Record<string, any>,
  tags: string[] = ["wordpress"]
)

Source from the content-addressed store, hash-verified

49
50// Core fetch - throws on error (for functions that require data)
51async function wordpressFetch<T>(
52 path: string,
53 query?: Record<string, any>,
54 tags: string[] = ["wordpress"]
55): Promise<T> {
56 if (!baseUrl) {
57 throw new Error("WordPress URL not configured");
58 }
59
60 const url = `${baseUrl}${path}${query ? `?${querystring.stringify(query)}` : ""}`;
61
62 const response = await fetch(url, {
63 headers: { "User-Agent": USER_AGENT },
64 next: { tags, revalidate: CACHE_TTL },
65 });
66
67 if (!response.ok) {
68 throw new WordPressAPIError(
69 `WordPress API request failed: ${response.statusText}`,
70 response.status,
71 url
72 );
73 }
74
75 return response.json();
76}
77
78// Graceful fetch - returns fallback when WordPress unavailable or on error
79async function wordpressFetchGraceful<T>(

Callers 15

getPostByIdFunction · 0.85
getCategoryByIdFunction · 0.85
getCategoryBySlugFunction · 0.85
getPostsByCategoryFunction · 0.85
getPostsByTagFunction · 0.85
getTagsByPostFunction · 0.85
getTagByIdFunction · 0.85
getTagBySlugFunction · 0.85
getPageByIdFunction · 0.85
getAuthorByIdFunction · 0.85
getAuthorBySlugFunction · 0.85
getPostsByAuthorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected