Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Make pagination work properly on a single-cpt.php template when pulling diff CPT

  • smarterwebpackages

    I want to casually describe this to prevent confusion and get me closer to the pagination at hand.

    1. Create a CPT for example: “movies”
    2. Create a CPT for example: “genre”
    3. Input several entries on the movie CPT
    4. Input one entry on the genre CPT for example: “scifi”
    5. Create a template for the genre CPT (single-genre.php)
    6. In single-genre.php, create a custom query to pull ALL “movies” to be displayed in the “scifi” entry of genre

    Number 6 works without an issue except pagination. It’s able to display a list of all “movie” cpt titles up to the maximum designated. It even shows the pagination properly. You can see the gist of single-genre.php code I coded.

    But pagination doesn’t work properly in single-genre.php. If this same code was placed on the “front-page.php”, it would work, I just needed to add use the line below:

    $paged = ( get_query_var( ‘page’ ) ) ? get_query_var( ‘page’ ) : $paged; // For static front pages

    MY QUESTIONS:
    1. Do you know how I can fix the pagination in this scenario where I’m pulling a queries of CPT (ex: movies) while putting it on a single-genre.php template of a different CPT (ex: genre)?
    2. Is there a custom php solution assuming I were to create a shortcode (or a block) so I can manually code PHP instead of simply using the somewhat limited query blocks?

    All I really care about is making pagination work. I have intentionally made the example simple enough to at least solve that problem first. Thank you for your help.

  • Hi there,

    Single post templates don’t support pagination by default because WordPress expects them to display only one post. Adding /page/2/ to a single post URL causes WordPress to get confused.

    Does the Genre need to be a CPT? You could switch it to a custom taxonomy instead, this would give you proper archive pages with built-in pagination.

    Right now, you’re trying to show a paginated list of one CPT (movies) inside the single post template of another CPT (genre), and WordPress doesn’t natively handle pagination in that context.

  • smarterwebpackages

    I completely understand what you’re saying and I’ll put the pagination issue to rest on a single post (I can make just use custom taxonomy instead). This issue is resolved.

  • Glad to hear that! 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.