Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/wordpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export async function getPostBySlug(slug: string): Promise<Post> {
}

export async function getAllCategories(): Promise<Category[]> {
return wordpressFetch<Category[]>("/wp-json/wp/v2/categories");
return wordpressFetch<Category[]>("/wp-json/wp/v2/categories?per_page=100");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Refactor to use query parameter objects for consistency and address silent truncation.

The implementation hardcodes ?per_page=100 directly in the URL path, which is inconsistent with the rest of the codebase. Other functions like searchCategories (line 330), searchTags (line 337), searchAuthors (line 344), and getAllPosts (line 191) properly use the query parameter object.

More critically, the hardcoded limit of 100 creates a silent truncation issue: if a WordPress site has more than 100 categories/tags/pages/authors, the functions will return incomplete data without any indication, despite their names suggesting they return "all" items. This contradicts the function semantics and could break UI components that expect complete data (e.g., app/posts/categories/page.tsx displays "All Categories").

Apply this diff to use query objects consistently:

 export async function getAllCategories(): Promise<Category[]> {
-  return wordpressFetch<Category[]>("/wp-json/wp/v2/categories?per_page=100");
+  return wordpressFetch<Category[]>("/wp-json/wp/v2/categories", { per_page: 100 });
 }
 export async function getAllTags(): Promise<Tag[]> {
-  return wordpressFetch<Tag[]>("/wp-json/wp/v2/tags?per_page=100");
+  return wordpressFetch<Tag[]>("/wp-json/wp/v2/tags", { per_page: 100 });
 }
 export async function getAllPages(): Promise<Page[]> {
-  return wordpressFetch<Page[]>("/wp-json/wp/v2/pages?per_page=100");
+  return wordpressFetch<Page[]>("/wp-json/wp/v2/pages", { per_page: 100 });
 }
 export async function getAllAuthors(): Promise<Author[]> {
-  return wordpressFetch<Author[]>("/wp-json/wp/v2/users?per_page=100");
+  return wordpressFetch<Author[]>("/wp-json/wp/v2/users", { per_page: 100 });
 }

Consider implementing proper pagination:

For sites with >100 items, implement pagination loops similar to getAllPostSlugs (lines 352-375) to fetch all pages of results, or rename these functions to indicate the limitation (e.g., getCategories with a limit parameter).

Also applies to: 260-260, 274-274, 288-288

🤖 Prompt for AI Agents
In lib/wordpress.ts around line 232 (and likewise at 260, 274, 288), the
function currently hardcodes "?per_page=100" in the URL which is inconsistent
with the rest of the module and silently truncates results; change the call to
pass a query object (e.g., { per_page: 100 }) to wordpressFetch for consistency,
and implement proper pagination to fetch subsequent pages (loop over page=1..n
using response headers or incrementing page until empty, like getAllPostSlugs)
so the function truly returns all categories (or else rename to a limited
getCategories/withLimit API and surface the limit).

}

export async function getCategoryById(id: number): Promise<Category> {
Expand Down Expand Up @@ -257,7 +257,7 @@ export async function getTagsByPost(postId: number): Promise<Tag[]> {
}

export async function getAllTags(): Promise<Tag[]> {
return wordpressFetch<Tag[]>("/wp-json/wp/v2/tags");
return wordpressFetch<Tag[]>("/wp-json/wp/v2/tags?per_page=100");
}

export async function getTagById(id: number): Promise<Tag> {
Expand All @@ -271,7 +271,7 @@ export async function getTagBySlug(slug: string): Promise<Tag> {
}

export async function getAllPages(): Promise<Page[]> {
return wordpressFetch<Page[]>("/wp-json/wp/v2/pages");
return wordpressFetch<Page[]>("/wp-json/wp/v2/pages?per_page=100");
}

export async function getPageById(id: number): Promise<Page> {
Expand All @@ -285,7 +285,7 @@ export async function getPageBySlug(slug: string): Promise<Page> {
}

export async function getAllAuthors(): Promise<Author[]> {
return wordpressFetch<Author[]>("/wp-json/wp/v2/users");
return wordpressFetch<Author[]>("/wp-json/wp/v2/users?per_page=100");
}

export async function getAuthorById(id: number): Promise<Author> {
Expand Down