Why is it always that I look for a solution for hours… then post it here and within a few minutes I find the solution myself….
I found the solution in this post.
The default arguments for get_posts() function include ‘numberposts’ => 5.
So when I set number, it was ignored and 5 was set for numberposts. The correct values are posts_per_page
and numberposts
(imo a poorly chosen variable).
Related Posts:
- What does setup_postdata ($post ) do?
- Query for custom post type? [closed]
- get_posts – get all posts by author id
- Exclude Current Post from Recent Posts Loop
- get_post random and order by not working
- get_posts with meta_compare=’LIKE’ not working
- Sort “get_pages” by menu order not ordering
- Get the exact SQL query that get_posts() generated
- get_posts inside cron
- get_posts returning empty array
- Problem with get_posts, tax_query and counting the number of posts
- Filtering custom post type query
- Check If posts exist in custom post type category, outside of loop
- data returned from get_post($postId) have different keys than wp-json/wp/v2/posts/{postId}
- How to limit get_posts()?
- meta_query date and time comparisons
- get_posts from post x(offset=>x) to end
- What’s the difference between “get_posts” and “wp_get_recent_posts” when used with “setup_postdata”?
- Increase the page size of the WordPress REST API
- How to generate a list of posts published on current day?
- Get latest posts from multiple categories
- get_posts() returns all posts rather than the ones specified with ‘post_author’ =>
- Get_Posts, only if in both categories
- Posts not showing in correct Alphabetical or ID order when using get_posts / orderby but only on production server
- get_posts() excluding all children of a specific post/page
- Secondary Query Is Breaking Main Query
- If clauses in get_posts query
- var_dump and print_r cause white screen
- excluding current post from get_posts
- How to query posts to include specific pages of one post type, and all pages of another post type?
- Only retrieve posts where post_excerpt has been filled out
- Can I use numberposts=-1 and offset together when using get_posts()?
- Ordering posts in get_posts
- How can I display a single post link, based on title sample and change monthly?
- get_posts() doesn’t consider user permissions
- Get posts inside Get terms problem
- Ho to add get_relative_date and post_except to this get_latest_post query?
- How to update all posts but the current one (post__not_in not working?)
- Only showing the_date and the_excerpt for first entry in get_posts
- Query Problem in getting top viewed posts
- get_posts not working as expected
- Get all pages and posts with get_pages() or get_posts()
- Getting only a specific post type with get_post?
- Exclude post format from get_posts
- Memory issue with get_posts( ) function
- get_posts() using an array of post ids [closed]
- Iterate over get_post_meta() result
- How can I show the author’s latest post with title?
- Unique Problem with the php date and get_posts
- get the post_date of ID
- Get posts by language in Polylang plugin
- Auto-change Post Status on First Page Load
- Not able to get random post
- Override Blog pages show at most with get_posts
- SQL query generated by WP_Query is not the same what request echoes
- Calling setup_postdata() causes “Call to undefined function get_userdata()” error?
- ‘child_of’ in get_posts not working
- Cron task firing but function not working
- wp json api – get posts by category
- Custom Post type Query post is not working
- Fetching All Posts (200+) in a Category – Performance Issues?
- Get all posts with a certain meta key, except for one with specific title
- How do I get only a certain number of images from a post (minus the featured image)?
- Modified home page query does not yield expected results
- Sort get_children by menu_order
- Working with get_posts parameters/arrays/strings
- Getting post by specific date in Advance Custom Field
- Add ul to its children with get_posts
- get_posts by id not working
- Select objects from get_posts()
- Using post title as term in query, only working with single word titles
- Single random post in homepage
- Get posts in archive page
- Paging result of get_posts in function
- How to get a custom post with the largest ID (not the last post by date)
- get_posts returning empty array
- Update all WordPress posts’s title and content then display them in a table
- get_post Question
- get the_content by ID and save the result to one array
- Zero posts returned with get_posts() on edit.php, but posts are returned on post.php
- Better way to query posts?
- Using get_posts, I need to use a combination of OR & AND relations
- Get number of posts in each category since last visit
- Get_posts not returning any posts when used with switch_to_blog
- get_posts array ‘between’ not behaving
- Get images by category
- How To Use get_posts & get_the_post_thumbnail Outside The Loop
- How to show only 1 post from a specific category on the front-page
- Query for draft or scheduled post
- get_posts() and ‘posts_per_page’ arg
- get_pages not returning any results or error when get_posts works
- Show posts in a list separated by day
- Function to get content by ID
- Display all Post titles with Category and Tag
- Intergrate WP into website
- Latest post on specific category and custom css
- Display post’s description and caption
- get posts based on category and post meta
- How to show only text from post in WordPress
- Install wordpress and replace database (from previous site)