• Resolved William Quade

    (@cusinndzl)


    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;
    ?>

    https://www.ads-software.com/extend/plugins/co-authors-plus/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    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.

    Thread Starter William Quade

    (@cusinndzl)

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

    Thread Starter William Quade

    (@cusinndzl)

    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?

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

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

    Thread Starter William Quade

    (@cusinndzl)

    <?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?

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

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

    Thread Starter William Quade

    (@cusinndzl)

    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 )

    Plugin Contributor Daniel Bachhuber

    (@danielbachhuber)

    Try using:

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Listing all pages by a co-author’ is closed to new replies.