0

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">
<ul>
<?php
$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'); ?>
            </a>
        <?php endif; ?>
    </li>
<?php endwhile; wp_reset_query();?>
</ul>
<div class="clear"></div>
</div>

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

1 Answer 1

1

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 and acknowledge you have read our privacy policy.

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