简体   繁体   中英

Wordpress author page pagination per post type

I have an author page where I display author posts and author custom posts.

I tried to add a pagination for custom posts, but it redirects to multisite homepage. Is it an issue with nginx config / site setup or my code?

Source: https://sochi.asp.sale/author/svetlanapolyakova/

I use this pagination code:

<div class="pagination">
    <?php 
    $url = 'https://' . $_SERVER['SERVER_NAME'];
    $author = get_the_author_meta('user_nicename', $curauth->ID);

        echo paginate_links( array(
            'base'         => $url . '/author/%_%',
            'total'        => $wp_query->max_num_pages,
            'current'      => max( 1, get_query_var( 'paged' ) ),
            'format'       => $author . '/?paged=%#%',
            'show_all'     => false,
            'type'         => 'plain',
            'end_size'     => 2,
            'mid_size'     => 1,
            'prev_next'    => true,
            'prev_text'    => sprintf( '<i></i> %1$s', __( 'Новее', 'text-domain' ) ),
            'next_text'    => sprintf( '%1$s <i></i>', __( 'Старее', 'text-domain' ) ),
            'add_args'     => false,
            'add_fragment' => '',
        ) );

    ?>
</div>  

You have to add below code to your function.php of your active theme

function custom_type_archive_display($query) {
    if (is_post_type_archive('custom_post_type')) {
        $query->set('posts_per_page',1); //Here add number of posts you want to display per page
        return;
    }
}

add_action('pre_get_posts', 'custom_type_archive_display');

Tested and works well

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM