0

I'm working on the author.php page and showing custom post types created by that user. Everything's working great except the pagination. Can anyone tell me what I'm doing wrong? Thanks!

<?php get_header(); ?>
<?php if (1 == ($paged = (get_query_var('paged') ?: 1))): ?>
    <section class="posts-container">
        <div class="container">
            <h2 style="text-transform: uppercase;">Posts from <?php echo get_the_author_meta( 'display_name', $author ); ?></h2>

            <?php
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $args = array(
                'post_type'      => array( 'style' ),
                'post_type'      => array( 'travel' ),
                'posts_per_page' => 1000,
                'author'         => $author,
                'paged'=>$paged,
            );
            $author_videos = new WP_Query( $args );
            if ( $author_videos->have_posts() ) : while ( $author_videos->have_posts() ) : $author_videos->the_post(); ?>

                <?php get_template_part('partials/single', 'post'); ?>

            <?php endwhile; ?>

                <div class="clear"></div>

                <div class="nav-previous alignleft">
                    <?php next_posts_link( 'Older posts' ); ?>
                </div>
                <div class="nav-next alignright">
                    <?php previous_posts_link( 'Newer posts' ); ?>
                </div>

            <?php wp_reset_postdata(); ?>

            <?php endif; ?>

        </div>
    </section>
<?php endif; ?>
2
  • Use pre_get_posts to alter the main query, don't create a new query in the template.
    – Milo
    Aug 21, 2018 at 15:28
  • Thanks for your response. Can you give me an example I don't understand I'm afraid?
    – Tommy
    Aug 21, 2018 at 16:07

1 Answer 1

0

have you already tried this way?

<section class="posts-container">
    <div class="container">
        <h2 style="text-transform: uppercase;">Posts from <?php echo get_the_author_meta( 'display_name', $author ); ?></h2>

        <?php
        $args = array(
            'post_type'      => array( 'style', 'travel' ),
            'posts_per_page' => -1,
            'author'         => $author
        );

        $author_videos = new WP_Query( $args );
        if ( $author_videos->have_posts() ) : while ( $author_videos->have_posts() ) : $author_videos->the_post(); ?>

            <?php
              // I think you should use archive rather than single
              // get_template_part('partials/archive', 'post');
                 get_template_part('partials/single', 'post');
            ?>

        <?php endwhile; ?>

            <div class="clear"></div>

            <div class="nav-previous alignleft">
                <?php next_posts_link( 'Older posts' ); ?>
            </div>
            <div class="nav-next alignright">
                <?php previous_posts_link( 'Newer posts' ); ?>
            </div>

        <?php wp_reset_postdata(); ?>

        <?php endif; ?>

    </div>
</section>
3
  • Thanks for your response. The archive partial doesn't work I'm afraid.
    – Tommy
    Aug 21, 2018 at 16:08
  • Does pagination work using the single template?
    – benny-ben
    Aug 21, 2018 at 16:30
  • Unfortunately not
    – Tommy
    Aug 22, 2018 at 8:09

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.