• Resolved Patrick Daly

    (@developdaly)


    The Problem

    I’m unable to do any sort of pagination (built in or plugin) with a WP_Query on a singular post type page using custom permalinks.

    Pagination does work with the default permalink structure.

    The Code

    Registering the Post Type

    /* Arguments for the client post type. */
    $client_args = array(
    	'labels' => $client_labels,
    	'capability_type' => 'page',
    	'public' => true,
    	'can_export' => true,
    	'query_var' => true,
    	'rewrite' => array( 'slug' => 'client', 'with_front' => false ),
    	'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', "{$prefix}-post-settings", 'entry-views' ),
    	'taxonomy' => array( 'category' )
    );
    
    register_post_type( apply_filters( 'mba_client_post_type', 'client' ), apply_filters( 'mba_client_post_type_args', $client_args ) );

    The Loop

    <?php
    $slug = basename(get_permalink());
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $args = array( 'posts_per_page' => '-1', 'post_type' => 'press', 'clients' => $slug, 'paged' => $paged );
    $wp_query->query($args);
    ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    
    <!-- do stuff -->
    
    <?php endwhile; ?>
    
    </div><!-- .gallery -->
    <?php previous_posts_link(); ?>
    <?php next_posts_link(); ?>
    <?php $wp_query = null; $wp_query = $temp; ?>
    <?php wp_reset_query(); ?>

    Template

    My post_type is client so I’m using client.php to show the singular post. The template then pulls in posts from another post type, press. The press posts should pagination.

    Desired URLs: https://maxborgesagency.com/client/ibuypower/ and https://maxborgesagency.com/client/ibuypower/page/2/

    Currently when you go to https://maxborgesagency.com/client/ibuypower/page/2/ you are redirected back to https://maxborgesagency.com/client/ibuypower/

    So those desired URLs don’t work, but these do when the permalink structure is set to default: https://maxborgesagency.com/?client=ibuypower&paged=2

    I’m thinking that WordPress just isn’t able to understand the rewritten URL properly.

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Post Type Singular Page with Pagination’ is closed to new replies.