• Resolved Beee

    (@beee)


    I have changed the permalink for author pages from author to member, because we use the archive page as a profile page.

    I used this function for it:

    function change_author_permalinks() {
        global $wp_rewrite;
        $wp_rewrite->author_base = 'member';
        $wp_rewrite->flush_rules();
    }
    add_action( 'init', 'change_author_permalinks' );

    That works as expected.
    Result https://domain.com/member/author-name/

    I then wanted to create subpages for the author so I rewrote the address of any subpages and showed content accordingly to a query var.

    I used this code for it:

    function idf_rewrite_profile_pages() {
        add_rewrite_rule( 'member/([a-z-]+)/([a-z-]+)/?$', 'index.php?author_name=$matches[1]&subpage=$matches[2]', 'top' );
    }
    add_filter( 'init', 'idf_rewrite_profile_pages', 1, 3 );
    

    That also works as expected.
    Result https://domain.com/member/author-name/name-subpage/

    I created a subpage named ‘written’ on which I list the loop/first page of posts:
    https://domain.com/member/author-name/written/.

    That works.

    Paging is activated and links https://domain.com/member/author-name/writte/page/2/ (as expected).

    The query for the subpage ‘written’: author_name=[name of author]&subpage=written
    If I check the query for the paged subpage of written the query is: paged=2&pagename=member%2F[author name]%2Fsubpage=written

    I would expect it be something like: paged=[page number]&author_name=[author name]&subpage=written

    How do I make my archive sub-pages work on a rewritten subpage/url ?

    • This topic was modified 7 years, 2 months ago by Beee.
    • This topic was modified 7 years, 2 months ago by James Huff.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Like any query for posts in WP, use the “pre_get_posts” action to alter it. In your callback, first be sure the passed query applies to the situation you need to change. You can get any query var with WP_Query::get() and change or add any valid query var with WP_Query::set(). In your actual code, don’t use the :: class reference, use the -> object reference, for example $query->set('paged', 2 );

    Thread Starter Beee

    (@beee)

    Thanks for the reply @bcworkz.

    I’m not sure if I need pre get posts. I list the posts on the author archive page, albeit with a query var to create a subpage.

    The ‘page’ in question is the author page. So the query already exists because I can list page one a fake subpage of the author page.

    The normal structure of paged archives does work, so https://domain.com/member/author-name/page/2/

    But I like to have written in it. Maybe that’s an easier question. How do I get written in there ??

    This is my ‘view’: https://imgur.com/a/rj5gy

    The address is where I show my posts. The marked red in the bottom is a mouse hover over page 2 of the pagination. Pagination sees the correct url but the posts are not retrieved there.

    Thread Starter Beee

    (@beee)

    And suddenly it clicked…

    I removed all my (involved) rewrites, clicked page 2 and examined the query again.

    I copied it as I saw and worked from there inserting variables. I think while testing I also removed my permalink which is stated above, that’s probably why I got a different result than expected.

    This did the trick.

    add_rewrite_rule( 'member/([a-z-]+)/written/page/([0-9]+)/?$', 'index.php?paged=$matches[2]&author_name=$matches[1]&subpage=written', 'top' );

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination for author archive subpage seen as page’ is closed to new replies.