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

Function getAllPosts

lib/wordpress.ts:194–214  ·  view source on GitHub ↗
(filterParams?: {
  author?: string;
  tag?: string;
  category?: string;
  search?: string;
})

Source from the content-addressed store, hash-verified

192}
193
194export async function getAllPosts(filterParams?: {
195 author?: string;
196 tag?: string;
197 category?: string;
198 search?: string;
199}): Promise<Post[]> {
200 const query: Record<string, any> = {
201 _embed: true,
202 per_page: 100,
203 };
204
205 if (filterParams?.search) query.search = filterParams.search;
206 if (filterParams?.author) query.author = filterParams.author;
207 if (filterParams?.tag) query.tags = filterParams.tag;
208 if (filterParams?.category) query.categories = filterParams.category;
209
210 return wordpressFetchGraceful<Post[]>("/wp-json/wp/v2/posts", [], query, [
211 "wordpress",
212 "posts",
213 ]);
214}
215
216export async function getPostById(id: number): Promise<Post> {
217 return wordpressFetch<Post>(`/wp-json/wp/v2/posts/${id}`);

Callers 1

sitemapFunction · 0.90

Calls 1

wordpressFetchGracefulFunction · 0.85

Tested by

no test coverage detected