WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just want to get the most latest posts by an author. I am using get_posts at the moment but I notice it doesn't take an author argument, so how I can I specify my author?

$args = array( 'numberposts' => '1');
$posts=get_posts( $args );
foreach($posts as $post)
{                           
    setup_postdata($post);
    //do stuff
}
share|improve this question
up vote 0 down vote accepted

$args = array( 'author' => 1, 'numberposts' => 1 ); The author parameter isn't documented on the get_posts() codex page, but it does work.

share|improve this answer

Quick google reveals http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters

Look at using wp_query() with author parameters and a limit of 1 post.


Note to editors: don't complain about me putting a link instead of typing the answer. I realise is is normally needed in case the link disappears, but since it is a link to the codex, this website will disappear before that link stops working. Peace.

share|improve this answer
1  
$args = array( 'author' => 1, 'numberposts' => 1 ); The author parameter isn't documented on the get_posts() codex page, but it does work. – developdaly Sep 6 '12 at 3:17
    
@developdaly this worked. Thank you. DO you want to put this comment as an answer and I will mark it correct? – Nicola Sep 6 '12 at 8:30
    
@developdaly please type that as an answer so I can complete this qustion – Nicola Sep 24 '12 at 10:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.