Exercise 3: WP_Query vs. get_posts() for a Paginated, Filtered List — Possible Solution ==================================================================== THE ANSWER: WP_Query ------------------------------ WP_Query is the better tool for this specific requirement. WHY, PER THIS CHAPTER'S OWN COMPARISON TABLE ------------------------------ Per this chapter's own table, WP_Query "returns a full query object with pagination support" and is "the right choice for anything needing pagination or deeper query control." get_posts(), by contrast, "returns a plain array - no built-in pagination" and is described as "the right choice for a quick, simple list with no pagination needed." WHY PAGINATION SPECIFICALLY RULES OUT get_posts() ------------------------------ The developer's stated requirement explicitly includes "next page" / "previous page" navigation - a genuine pagination requirement, not just a fixed list of posts. Per this chapter, get_posts() has no built-in pagination support at all; it simply returns a plain array of however many posts were requested, with no mechanism for tracking pages, total post counts, or generating next/previous navigation. Building pagination on top of get_posts() manually would mean re-implementing functionality WP_Query already provides directly. WHY WP_Query'S OWN QUERY-OBJECT NATURE MATCHERS THIS NEED ------------------------------ Because WP_Query returns "a full query object with pagination support" rather than a plain array, it carries the additional information (like total number of pages, current page number) genuinely necessary to build real "next page"/"previous page" navigation controls - information a plain array from get_posts() simply doesn't carry along with it. WHY THE CATEGORY FILTER DOESN'T CHANGE THE CONCLUSION ------------------------------ Both WP_Query and get_posts() are shown in this chapter's own examples successfully filtering by category_name - that particular requirement alone doesn't favor one tool over the other, since both can express it. The deciding factor here is specifically the pagination requirement, which only one of the two tools genuinely supports out of the box. WHY THIS WORKS AS AN ANSWER ------------------------------ It states the correct tool and justifies the choice using this chapter's own explicit comparison table, isolates pagination as the specific requirement that decides the answer, and explicitly addresses why the category-filtering requirement alone wouldn't have been sufficient to decide between the two tools.