Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Post Type Authors Page WordPress

  • SOLVED

I'm trying to create a simple authors page restricted to a specific (custom) post type. I would like to display each author, some of their basic meta data (name, bio), and links to the posts of the specified type credited to them (X most recent if possible). Thanks!

Answers (2)

2010-07-27

Aneesh Joseph answers:

<?php
require('/the/path/to/your/wp-blog-header.php');
?>

<?php get_header(); ?>
<div id="contet">
<?php $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");
<!-- loop for authors -->
foreach($authors as $author) {
$curauth = get_userdata(intval($author->ID));
?>



<h2>About: <?php echo $curauth->nickname; ?></h2>
<dl>
<dt>Website</dt>
<dd><a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a></dd>
<dt>Profile</dt>
<dd><?php echo $curauth->user_description; ?></dd>
</dl>

<h2>Posts by <?php echo $curauth->nickname; ?>:</h2>

<ul>
<!-- Posts Loop -->


<?php query_posts('author='.$author->ID.'&showposts=5'); while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></li>
<?php endwhile; ?>


<!-- /Posts Loop -->

</ul>

<?php } ?>
<!-- /loop for authors -->

</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>


Use this php file after editing it with proper path to wp-blog-header.php and try accessing this via your browser :)

If you want to give a nice Permalink to this page, then use htaccess rewrite rules :)


Adam Bundy comments:

Aneesh, this is really close, but I need to restrict the query_posts to a custom type (iW_post), which Ive tried to do here, but the output shows the same 5 posts for each author. Can you help get the custom type integrated? Thanks!


<?php $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");
foreach($authors as $author) {
$curauth = get_userdata(intval($author->ID));
?>

<h2>About: <?php echo $curauth->nickname; ?></h2>
<dl>
<dt>Website</dt>
<dd><a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a></dd>
<dt>Profile</dt>
<dd><?php echo $curauth->user_description; ?></dd>
</dl>

<h2>Posts by <?php echo $curauth->nickname; ?>:</h2>

<ul>
<!-- Posts Loop -->

<?php query_posts( array( 'post_type' => 'iW_post', 'showposts' => 5, 'author='.$author->ID ) ); while (have_posts()) : the_post(); ?>

<li><? echo $curauth->id;?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></li>

<?php endwhile; ?>

<!-- /Posts Loop -->
</ul>

<?php } ?>


Aneesh Joseph comments:

<?php query_posts( array( 'post_type' => 'iW_post', 'showposts' => 5, 'author'=>$author->ID ) ); while (have_posts()) : the_post(); ?>

:)


Adam Bundy comments:

Hey Aneesh- that's identical to what I have (see above source). Its working to echo posts, but the posts loop is not resetting for each author- I see same 5 posts for each author. Thanks!


Adam Bundy comments:

Hold up, found the difference. Thanks Aneesh. Testing now...


Adam Bundy comments:

Awesome Aneesh- that worked. How difficult would it be to modify the author query below to include only authors who have at least one iW_post?

<?php $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");


Aneesh Joseph comments:


$authors = $wpdb->get_results("SELECT ID
FROM $wpdb->users
WHERE EXISTS
(SELECT post_author
FROM $wpdb->posts
WHERE $wpdb->users.ID = $wpdb->posts.post_author
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'iW_post')
ORDER BY display_name");


Adam Bundy comments:

Rock n' Roll! Thanks Aneesh!

2010-07-27

Pippin Williamson answers:

This is the link you need.

http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html

If you need help implementing it, let me know at [email protected]


Adam Bundy comments:

Pippin thanks but Im actually looking to create a page that lists ALL authors, some info and links to the posts (custom post type) they're owners of, not an 'about the author' box. Thanks though!