I am wondering if any has looked at the example for this tag. I am trying to figure out if there is a typo. It reads "if you want to list last 5 posts, but the code is getting the last 10. I am new to the "wiki"/"codex" environment, so I don't want to do anything or try to do anything until I get some feedback. I tried to bring it up at the support forum, but received no feedback.Miklb 05:22, 8 Jun 2005 (UTC)
Note that if you use the $posts variable, and you include this code before your main article code, you will break things. Better to use another variable if you do not want to break the normal article loop after this code is done. -- Nils 04:56, 13 Dec 2005 (GMT)
Correct me if I'm wrong, but shouldn't it say numberposts where it instead says posts_per_page? I've looked into the source code and that appears to be what it uses to limit the number of posts. Marcus1060 04:17, 15 December 2010 (UTC)
Can anyone elaborate on how to force future posts to be returned by get_posts
as well? I want to put a list of coming events in my sidebar (coming events are all in one category). Thanks. — Sam Wilson 06:09, 20 Aug 2007 (UTC)
I think that, as of 2.6, orderby=post_title must instead be orderby=title.
It seems that 2.6 has drastically changed the get_posts() function, now using an instance of WP_Query to query the database. The documentation here says that you can use "orderby=post_title", however this stopped working as of 2.6. I believe that it's because WP_Query doesn't support "post_title".
Line 1241 of query.php reads... $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand');
Forgive me for my slight cluelessness, I'd love to set it up so that I can have just one post per category followed by a list of other posts, but I'm not sure where to put the code? Particularly since it appears to be calling a specific category, I'm not sure where it should go.
Is there a way to do this so that it will work for every category?
@Scribu -
I saw that you undid my recent addition to this page. No hard feelings, it may not be the right place to do this - but the fact remains that get_posts() produces unexpected results when using it with custom post types.
For example, calling this:
get_posts('numberposts=1&post_type=movie&genre=action');
will not work, especially if 'genre' is a hierarchical taxonomy. I've had to revert to using raw mysql queries instead of get_posts, query_posts, or re-instantiating WP_Query.
Hence the text I've struck through on this page (what you reverted).
Again: for sure, the right place to address such issues is Trac, but shouldn't the function reference page reflect the outcome one can expect from using the function, and warn users about possible problems?
This page, which is a critical page for any theme developer, needs serious attention by those who know the API well (I unfortunately do not, which is why I'm quite confounded). The last section talks about < 2.5 parameters, listing them cryptically as PHP variables eg: $category. But the function signature at the top of the page declares: get_posts($arguments), and later you discover that $arguments can be a hash of parameters (that are listed on the_query page - more cross-referencing). None of this corresponds with the < 2.5 parameters, and yet the documentation states that you can use all of the pre 2.5 parameters (eg: $category) along with this new-style declaration. Please help all future developers by cleaning this confusion up! I would do my part here, but I'm one of those who are confused! Tomaugerdotcom@yahoo.ca 21:45, 7 December 2010 (UTC)
Isn't "author" an argument of get_posts()?
I believe the claim in the "Return Value" section that "get_posts() will return private pages in the appropriate context (i.e., for an administrator)" is no longer true. See the get_posts() function in wp-includes/post.php Topdownjimmy 16:43, 6 November 2013 (UTC)
Passing an array of ids as include value makes any values for the order and orderby arguments mute. Wouldn't the expected behaviour be to sort the included ids like any "WHERE ... IN (.., .., ..) ORDER BY ... " type of MySQL-query?