-
Notifications
You must be signed in to change notification settings - Fork 274
fix: add ?per_page=100 to tags, categories, pages, authors
#68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@2u841r is attempting to deploy a commit to the 9d8 Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughFour API fetching functions in the WordPress library ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5–10 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/wordpress.ts(4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
Repo: 9d8dev/next-wp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-06-26T17:28:47.375Z
Learning: Paginate content with a sensible default (e.g., 9 posts per page) to balance performance and usability.
📚 Learning: 2025-06-26T17:28:47.375Z
Learnt from: CR
Repo: 9d8dev/next-wp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-06-26T17:28:47.375Z
Learning: Define all TypeScript interfaces for WordPress entities (Post, Page, Category, Tag, Author, Media) in a dedicated type definition file (e.g., lib/wordpress.d.ts) to ensure strict typing and maintainability.
Applied to files:
lib/wordpress.ts
🧬 Code graph analysis (1)
lib/wordpress.ts (5)
lib/wordpress.d.ts (4)
Category(106-109)Tag(111-113)Page(81-93)Author(115-124)app/posts/page.tsx (1)
Page(35-164)app/posts/categories/page.tsx (1)
Page(15-37)app/posts/authors/page.tsx (1)
Page(15-35)app/posts/tags/page.tsx (1)
Page(15-35)
|
|
||
| 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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
otherwise, can be confusion.
and in most case- tags and categories for personal, even business blog exceed 10 but not 100.
request: update README
Summary by CodeRabbit