WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

If $a contains the ID of a certain post, how can one obtain the corresponding author ID? I've tried with

$b = get_post( $a);
$c = $b->post_author;
$d = $c->ID;

but it does not work.

share|improve this question
up vote 1 down vote accepted
$b = get_post( $a);
// post_author already contain author ID. 
//So you can assign author's ID to $c same as to $d
$c = $d = $b->post_author;
share|improve this answer
A few words along with the code would be both easy to read and more informative. – tfrommen Nov 7 '13 at 12:10
'answer' where comment longer than actual answer. – qwerty qwerty Nov 7 '13 at 12:15
Yes, that's right. But that's also what this is about. A block of code without an explanation can satisfy the user, who asked the question. If the answer does exactly what was asked for, and if there are no side effects, config stuff and the like. A real answer, consisting of a block of code, along with some in-code comments, and maybe some actual text before and/or after, however, could also help users stopping by later, who may have a very similar problem. When they understand why the code is working and what it is doing, the maybe can help themselves... – tfrommen Nov 7 '13 at 12:21

You have the author id

Let me explain.

// gets the post detail from the post id
$b = get_post( $a);
// This is the author id, as the post_author is the id of the author
$c = $b->post_author;

So $c contains the author id

share|improve this answer
$b = get_post( $a);
$c = $b->post_author;

here $c gets the author id. $b->post_author returns author id

share|improve this answer

Your Answer


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.