0

Hi to the community!!!

I need some help with pagination in author.php template.
I have pagination working in all my loops except in authors.php that i get a 404 error.
In my settings/reading i have set blog posts to show as 1.

The first step was the author rewrite from author to artist,

function set_new_author_base() {
    global $wp_rewrite;
    $author_slug = 'artist';
    $wp_rewrite->author_base = $author_slug;
}
add_action('init', 'set_new_author_base');

In the author.php template i query the $author-ID posts in the custom post type 'ideas':

<?php 
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
query_posts('post_type=ideas&author='.$curauth->ID.'&posts_per_page=1&paged='.$paged);
if(have_posts()) : while(have_posts()) : the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile;
previous_posts_link('newer');
next_posts_link('older');
endif;
?>

for some reason i get a 404, in the other side, i can run queries in taxonomy.php, home.php, index.php... with pagination also and it works fine.

i see the next and previous links that point me here: http://domain.dev/artist/philip/page/2/ but i get the 404 error,

the query in home.php template:

<?php //*The Query*//
query_posts($query_string . '&post_type=ideas&posts_per_page=1&offset=0&paged='.$paged);
if(have_posts()) : while(have_posts()) : the_post();
?>

here i correctly get next and previous posts http://domain.dev/ideas/page/2/

the query in index.php template:

<?php //*The Query*//
query_posts($query_string . '&posts_per_page=1&offset=0&paged='.$paged);
if(have_posts()) : while(have_posts()) : the_post();
?>

here i correctly get next and previous posts http://domain.dev/ideas/page/2/

do you understand what is going on here???
i'm sure that the author have some posts, i have flush the rules...

thanks a lot!

1 Answer 1

3

i found a solution to my problem!

function custom_author_archive( &$query ) {
    if ($query->is_author)
        $query->set( 'post_type', 'idea' );
}
add_action( 'pre_get_posts', 'custom_author_archive' );

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.