• Resolved isaacbenh

    (@isaacbenh)


    In my front-page.php I’m looping over a custom post-type and I want to add pagination. The pagination links appear, but when I click its like nothing has changed. Same data appear even though URL has changed. Not sure what is wrong.
    This is part of what I added when I registered the new post-type

    'label' => 'Tweet',
    		'public' => true,
    		'has_archive' => true,
    		'taxonomies' => array( 'category' ),
    		'rewrite' => array( 'slug' => 'tweet', 'with_front' => true ),
    		'supports' => array( 'title', 'thumbnail', 'editor', 'author' )
    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    
    $args = array(
        'post_type' => array( 'post', 'tweet' ),
    	'posts_per_page' => 4,
    	'orderby'=> 'menu_order',
    	'paged' => $paged
    );
    $the_query = new WP_Query( $args );
    ?>
    
    <div class="col-md-6 col-md-offset-3">
    
    	<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    		<div class="page-header">
    			<h1><?php the_title(); ?></h1>
    			<?php if(get_post_type() === 'post') : ?>
    				<p><?php the_excerpt(); ?></p>
    			<?php else: ?>
    				<p><?php the_content(); ?></p>
    			<?php endif; ?>
    		</div>
    
    	<?php endwhile; endif; ?>
    
    	<?php
    		$big = 999999999; // need an unlikely integer
    
    		echo paginate_links( array(
    			'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    			'format' => '?paged=%#%',
    			'current' => max( 1, get_query_var('paged') ),
    			'total' => $the_query->max_num_pages
    		) );
    	?>
    
    </div>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter isaacbenh

    (@isaacbenh)

    So I have to specify on WordPress settings that the front-page is my posts page and now it’s half working. I can only see 2 out of 4 pages. It shows in the pagination 4 pages, but 3-4 are empty.
    Any reason this is like that?

    Thread Starter isaacbenh

    (@isaacbenh)

    For now this solved it. Have no idea why.

    function include_post_type( $query ) {
        if ( $query->is_front_page() && $query->is_main_query() ) {
            $query->set( 'post_type', array( 'post', 'tweet' ) );
    		return;
        }
    }
    add_action( 'pre_get_posts', 'include_post_type' );

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pagination links appear, but new posts never load’ is closed to new replies.