• Resolved Overflow

    (@acrane)


    For some reason this exact code works on author.php, but only for 1 author not the other and it doesn’t work on my custom template page. What am I doing wrong?

    <?php
    /**
     * Template Name: pagination test
     */
    
    get_header(); ?>
    <?php //get_sidebar(); ?>
    <div id="page-left">
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $loop = new WP_Query( array(
    'post_type' => 'filmmaking',
    'posts_per_page' => 2,
    'paged'=> $paged
    ) ); ?>
    
    <?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
    <?php  endwhile;  ?>
    <?php endif; wp_reset_postdata(); ?>
    
    <?php previous_posts_link('&laquo; Nyare') ?>
    <?php next_posts_link(' ?ldre &raquo;') ?>
    
    </div><!-- page left -->
    <?php get_footer(); ?>
Viewing 1 replies (of 1 total)
  • Thread Starter Overflow

    (@acrane)

    Well, that’s usually the way it goes. You spend a whole day looking for something and once you post the question, you figure it out.

    Working code for a Custom Post Type paginated on a Custom Page Template: The biggest difference being that there is no, “if have posts” I don’t think I had seen it before but it works.

    <?php
    /**
     * Template Name: pagination test
     */
    
    get_header(); ?>
    <?php //get_sidebar(); ?>
    <div id="page-left">
    <?php
    $wp_query = new WP_Query();
    $wp_query->query(array(
    	'post_type'=>'filmmaking',
    	'paged' => $paged,
    	'posts_per_page' => 2,
    ));
    
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
    <?php  endwhile; ?>
    <?php wp_reset_postdata(); ?>
    
    <?php previous_posts_link('&laquo; Nyare') ?>
    <?php next_posts_link(' ?ldre &raquo;') ?>
    
    </div><!-- page left -->
    <?php get_footer(); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Type Pagination not workng’ is closed to new replies.