Maybe this is really simple, but I can’t get it to work. in my author.php file which is used when looking at individual authors, I list the usual: name, description and so on. I’d also like to list the posts the author has written (often written by multiple authors, hence the use of the co-authors plugin).
Would be great if someone could posts a code snippet for how to retrieve the posts by the current autho, when looking at their profile.
Maybe there is a simpler solution, but this is how we solved it in the end. We did a custom query which looked for posts where the current author was either post_author, or _coauthor. Then we output a list of all those posts. This is the code:
$querystr = "
SELECT DISTINCT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND (wposts.post_author = $curauth->ID OR (wpostmeta.meta_key = '_coauthor' AND wpostmeta.meta_value = $curauth->ID))
AND wposts.post_status = 'publish'
AND wposts.post_type = 'page'
ORDER BY wposts.post_title ASC
$pageposts = $wpdb->get_results($querystr, OBJECT);
<?php if ($pageposts): ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
<?php else : ?>
<?php endif; ?>
Viewing 1 replies (of 1 total)
The topic ‘[Plugin: Co-Authors] Listing all posts by coauthor on author.php’ is closed to new replies.