Ask your WordPress questions! Pay money and get answers fast! (more info)

Fix: all CPs appearing in author.php -I only want the author's CP

  • SOLVED

Fix: all CPs appearing in author.php but I only want the author's CP

This is my author.php... (see file attached) or [[LINK href="http://pastebin.com/R2M2y8pQ"]]Pastebin[[/LINK]]
I has been based around [[LINK href="http://wpquestions.com/question/showChronoLoggedIn/id/14245"]]this previous answer[[/LINK]]

On the each of the author's author.php page e.g. http://xyz.net/?author=X
it displays ALL of the CPs from the CPT teacher-profile, but I only want each author's page to show their teacher-profile CP.

I'd like someone to look through the code and get it back on track to only show only the author's CP on their author.php page

Answers (1)

2016-04-19

Andrea P answers:

it looks like the code is not retrieving the author ID.

instead of this

$authorid = get_the_author_meta( ID, $userID );


try this:

global $wp_query;
$curauth = $wp_query->get_queried_object();
$authorid = $curauth->ID;


if that doesn't work, you could also try other ways to retrieve the currently looped author id. like these:

$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
$authorid = $curauth->ID;

or

$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
$authorid = $curauth->ID;


pjeaje comments:

Thanks, that works. Is this way the most efficient?


Andrea P comments:

the examples above are all the same in term of efficency, they just depend on your wp version and how your template has been coded (some templates might be altering the main query and build up a different author pages loop).

the first sample is the most compatible, in my opinion, but if the others works, you could use any of them.


pjeaje comments:

thanks