Co-Authors Plus
[resolved] Advice for showing author profile page for authors without posts? (5 posts)

  1. notkristina
    Posted 3 years ago #

    My site includes some guest authors that don't yet have posts, but I would like them still to have profile pages.

    1. I've already successfully redirected the 404 page to use the author page template in the event that the query was for an author.
    2. I've extracted (from the query) the taxonomy term ID and slug of the co-author sought. This may not have been the most direct way to go about getting that information, but I have it.

    What I can't figure out is how to use the term ID or slug to pull a guest author's Co-Authors info, at the very least their display name and email. Do you have any advice?


  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    I think you can actually just hack it with something like this:

    add_action( 'template_redirect', 'capx_template_redirect' );
    function capx_template_redirect() {
    	global $wp_query;
    	if ( false !== stripos( $_SERVER['REQUEST_URI'], '/author' ) && empty( $wp_query->posts ) ) {
    		$wp_query->is_404 = false;
    		get_template_part( 'author' );

    Basically, it forces author.php to load if it would otherwise 404. Can you try that on for size?

  3. notkristina
    Posted 3 years ago #

    Thank you—this is a far better and tidier way of doing what I had done so far to force the 404 to load the author template, but even still the author info doesn't load on the page.

    In the widget that should show the author profile, it loads nothing. How can I tell it who the author is?

  4. notkristina
    Posted 3 years ago #

    For clarity's sake, here's a snippet of the author profile code from the author template, to show precisely how I'm calling the data. This retrieves the author info successfully on the pages of guest authors that have posts, but not on the author template when replacing a 404—possibly because instead of the author ID, the query is looking for the taxonomy term ID, which is a different number? But since it works on authors with posts, I'm not sure that makes any difference.

    echo get_the_author_meta('first_name').' '.get_the_author_meta('last_name');
  5. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 3 years ago #

    If you use get_queried_object() on an author.php template, it should give you an $author object (which is just a user object). You could do something like:

    $author = get_queried_object();
    echo $author->first_name . ' ' . $author->last_name;

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Co-Authors Plus
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic