I’ll guess that you don’t set $authorid
anywhere, so it’s being ignored and returning all posts regardless of author. If you enable debugging, you’ll get a warning telling you that $authorid
is undefined. It’s good practice to always develop with debugging enabled, so you don’t have to guess what your errors are.
Also, don’t use query_posts
for additional queries, or ever actually! It overwrites the original main query, and may produce unpredictable results elsewhere in your template. Use WP_Query
instead:
$args = array(
'post_type' => 'my_custom_post_type' ,
'author' => get_queried_object_id(), // this will be the author ID on the author page
'showposts' => 10
);
$custom_posts = new WP_Query( $args );
if ( $custom_posts->have_posts() ):
while ( $custom_posts->have_posts() ) : $custom_posts->the_post();
// your markup
endwhile;
else:
// nothing found
endif;
Note in the case of a custom query, we assign posts to $custom_posts
(or whatever unique variable name you’d like to use), and then reference that within the loop.