1

I have looked high and low for an answer to this question and all I keep finding is how to make an archive page that list all authors and their post (including cpt's). I've tried to adapt these pages, but I still can't get just the author of a single post that happens to be in a custom post type.

I just simply want to get the author of the current post which happens to be in a custom post type, which for one reason or another seems to be just about impossible.

Can somebody please, please, please hook me up with a function or anything that can just simply get the author of the current post that happens to be in a custom post type.

4
  • Did you try get_posts and within the loop getting the author method? Dec 2, 2013 at 8:18
  • 1
    There is absolutely no reason that the solutions that @ialocin suggested should not work unless, as he suggested, you are omitting information regarding your situation that we require to answer your question. We do not know if you are attempting to do this inside of the loop or outside, in a custom archive template file or in a plugin. We can't even confirm that you've been attempting this on a WordPress installation!! As ialocin said, we have absolutely no context for your question, and as such cannot aide you in resolving it without a million shots-in-the-dark.
    – bosco
    Jan 1, 2014 at 21:51
  • 1
    Please provide the code you are currently using that you perceive to be dysfunctional, detail where that code came from, and tell us exactly what you expect it to do that it is not doing. This is something you should strive to do for every question that you ask on WPSE! Simply stating that you've tried every author-related function "100 times" does absolutely nothing towards helping us understand what the problem is or what you have attempted to do to alleviate it. Help us help you, @JonFurry.
    – bosco
    Jan 1, 2014 at 21:56
  • 1
    Please review all of the articles in the "Asking" section of our help center to learn more about what goes into a good question.
    – bosco
    Jan 1, 2014 at 22:00

1 Answer 1

4

There are several functions for this available, like: the_author, for displaying; get_the_author, for returning. There is no restriction regarding custom post types, but those template tags only work inside the loop.
If you want to get more author information then the name you can use: the_author_meta, displaying; get_the_author_meta, returning. The latter two functions can also be used for getting author information outside the loop, for this you have to specify the second parameter $userID, which inside the loop isn't necessary. A basic example for this would be going like this:

global $post;
$a_id=$post->post_author;
the_author_meta( 'user_nicename', $a_id );

Take a look at this question and the answers for more outside the loop use cases.

3
  • I've tried all of these a 100 times.. I get the same results every time: the_author() -- blank. the_author_link() -- blank. -- the_author_meta() -- blank. I've resorted to making the author name go into a custom meta field and then just getting the meta field to use in place of the_author(). But obvioulsy Id prefer to do it legit.
    – Jon Furry
    Dec 3, 2013 at 0:35
  • 1
    Analyzing the problem is without the context is really hard. If you provide more information about the structure, the important pieces of code one should know, debug information and so on, I'm pretty sure there is a solution to be found. @JonFurry Dec 3, 2013 at 0:44
  • i've tried the above, didn't work at first... if you're working on the single.php template or something similar, try adding the_post(); one line before global $post; Sep 17, 2017 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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