• Resolved DarrenMooney

    (@darrenmooney)


    I’m using custom post type, in order to get pagination to work properly I had read that the CPT and the page must have different slugs.

    The code I found to get pagination to work:

    $my_query = new WP_Query ( array( 'post_type' => 'games-hub', 'posts_per_page' => 3, 'paged' => get_query_var('paged'), 'rewrite' => array( 'slug' => 'games', 'with_front' => true), ) ); 
    
    while ( $my_query->have_posts() ) : $my_query->the_post();
    ...

    However this has resulted in different slugs on the archive and and post URLs.

    Example:

    Archive: http://thegamersrepublic.net/games/
    Post: http://thegamersrepublic.net/games-hub/dishonored/

    The above is how I got pagination to work. However if you visit the following, pagination doesn’t work:

    Page: http://thegamersrepublic.net/games-hub/

    While the above page isn’t actually linked to, and chance are wouldn’t ever be visited, if there user does hit it by navigating to it manually, and tried to use the paging, they will get a 404.

    On top of that, I’m not all that happy with the inconsistent URLs with the archive and post (games/ & games-hub/).

    My intention (or hope) was for both the archive and page to use /games/.

    Simply, is there a way I can do without needing different slugs to get pagination to work for CPT? Or at least for them to work with the same slug?

    Thanks for any help that anyone can provide.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom post type, pagination and consistent slugs’ is closed to new replies.