I'm building a custom author.php template. I use this to get the author by slug

$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));

Now my loop uses the author's ID like this

<div class="author-products">
$args = array( 'post_type' => 'product', 'author_id'=> $curauth->ID );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <li><div class="author-product-title"><a href="<?php echo get_permalink( $loop->post->ID ) ?>">
        <?php the_title(); ?></a></div>
         <?php if ( has_post_thumbnail()) : ?>
            <a class="author-product-thumb" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
            <?php the_post_thumbnail('thumbnail'); ?>
        <?php endif; ?>
<?php endwhile; wp_reset_query();?>
<div class="clear"></div>

The loop is displaying all the posts and not filtering, is it a problem in the arguments?


Try 'author' => $curauth->ID instead of 'author_id'=> $curauth->ID since author_id is not a valid parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.