I am attempting to edit my author.php wordpress template to ensure that it shows posts by anyone author, only in one particular category. To date, I have been using the query_posts function which brings the course okay, although not the writer. Based on which way I actually do it, to date the posts either don't display whatsoever or all posts for the reason that category appear no matter the writer.

This is actually the appropriate code which I have seen cited with a wordpress.org admin, however it does not work with me and that i aren't able to find every other good examples. Any ideas why that does not work? Interesting help ahead of time.

//Gets author info to display on page and for use in query
<?php
    $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
?>

//Queries by category and author and starts the loop
<?php
    query_posts('category_name=blog&author=$curauth->ID;'); 
    if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

    //HTML for each post

<?php endwhile; else: ?>
    <?php echo "<p>". $curauth->display_name ."hasn't written any articles yet.</p>"; ?>
<?php endif; ?>

============ ALSO Attempted ============

<?php
    new WP_Query( array( 'category_name' => 'blog', 'author' => $curauth->ID ) );
?>

This does not work either, nevertheless it does filter the posts by author, simply not by category! What shall we be held doing wrong?

Thanks!

I simply had this same problem, that we solved utilizing a look for if(in_category('blog')) following the loop began, such as this:

if ( have_posts() ) : while ( have_posts() ) : the_post();
if(in_category('blog')) {
?>

    <!-- Loop HTML -->

<?php } endwhile; else: ?>
    <p><?php _e('No posts by this author.'); ?></p>

<?php endif; ?>

Obviously the $curauth check will come before.