I am trying to set up several archive pages (author.php and tag.php) that loop through a custom query. While I am able to utilize the instructions in the following link to create a custom query on a custom page template, I cannot seem to get pagination to work for me on a global template page.
For instance, I would like to be able to use the following link: site.com/author/author-name/ To pull up all of the custom post types called 'tasks' created by a specific author, utilizing author.php.
<?php global $paged, $wp_query; $qo = get_queried_object(); $author_id = $qo->ID; $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' )): 1; $args = array( 'author'=> $author_id, 'post_type'=> 'tasks', 'paged' => $paged ); $the_query = new WP_Query( $args ); // Pagination fix $temp_query = $wp_query; $wp_query = NULL; $wp_query = $the_query; if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> the_title(); endwhile; endif; wp_reset_postdata(); //OPTION 1 for pagination from Wordpress Codex sample $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages ) ); // OPTION 2 Custom query loop pagination // previous_posts_link( 'Older Posts' ); // next_posts_link( 'Newer Posts', $the_query->max_num_pages ); wp_reset_query(); $wp_query = NULL; $wp_query = $temp_query; ?>
With option 1, the url that is set up for next links is: site.com/author/author-name/?paged=x Whereas, with option 2, the url that is set up for next links is: site.com/author/author-name/page/x
In both cases, when I click on the next page, I am directed to a 404 error. The key here is that I need the author name to be dynamic, so as I set up new users, I can pull up their custom posts using one of the above structures (preferrably site.com/author/author-name/page/x or even site.com/author-name/page/x).
Any insight would be greatly appreciated.