WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
[resolved] Listing all pages by a co-author (9 posts)

  1. cusinndzl
    Member
    Posted 1 year ago #

    I have a website and I'd like to be able to list all of the pages by a particular co-author.

    So far I have this code which will list all of the pages by an author showing the title of the post and having the title linked to the actual post. The problem is that it only will list posts where the co-author is the primary author listed first. All other posts by that author aren't shown.

    Could you help me out? I like how this code works, I just need it to list all of the posts by the author, and just not the ones where they are the primary author.

    <?php
        $author_id = get_queried_object()->post_author;
        $my_pages = wp_list_pages('authors='.$author_id.'&sort_column=post_name&echo=0&title_li=');
        $var1 = '<a';
        $var2 = '<a';
        $var3 = '</a>';
        $var4 = '</a>';
        $my_pages = str_replace($var1, $var2, $my_pages);
        $my_pages = str_replace($var3, $var4, $my_pages);
        echo $my_pages;
    ?>

    http://wordpress.org/extend/plugins/co-authors-plus/

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    I've put together a piece of documentation explaining how to query for all posts (or pages) from an author. Check it out, and let me know any specific questions you have.

  3. cusinndzl
    Member
    Posted 1 year ago #

    Thanks a lot. I'll let you know if I need any more help.

  4. cusinndzl
    Member
    Posted 1 year ago #

    I put the code into the website and I get the unexpected T_VARIABLE parse error on line seven of the code on your website. I just wrapped all of the sample code in <?php ?>. What's my issue?

  5. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    Can you share what code you used? The example I've published is intended as a guide, not what you should use verbatim.

  6. cusinndzl
    Member
    Posted 1 year ago #

    <?php
    
    // Get the author term based on a variable called $user_login
    global $coauthors_plus;
    $coauthor = $coauthors_plus->get_coauthor_by( 'user_login', $user_login );
    $coauthor_term = $coauthors_plus->get_author_term( $coauthor )
    
    // Build the query arguments
    $args = array(
        'post_type' => 'post',
        'posts_per_page' => 10,
        'post_status' => 'publish',
        'tax_query' => array(
            array(
                'taxonomy' => 'author',
                'field' => 'slug',
                'terms' => $coauthor_term->slug,
            ),
        ),
    );
    $author_query = new WP_Query( $args );
    
    if ( $author_query->have_posts() ) :
        while ( $author_query->have_posts() ) : $author_query->the_post();
    
        // Do your presentation
    
        endwhile;
    endif;
    
    ?>

    Would would I need to modify to get it working?

  7. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    The // Do your presentation is a code comment. You'd need to fill it in with the presentational code you need.

  8. cusinndzl
    Member
    Posted 1 year ago #

    I managed to get it to display posts for the logged in user. How do I modify this code to get the author of the current page, and not the logged in user.

    get_coauthor_by( 'user_login', $user_login )

  9. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    Try using:

    get_coauthor_by( 'ID', get_queried_object()->post_author );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic