-
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 genreNumber 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.
-
Alvind
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.
-
Alvind
Glad to hear that! 🙂
- You must be logged in to reply to this topic.