• I’m using template part for showing portfolio items. It’s not page template just portfolio.php file and I’m included it with get_template_part(‘portfolio’); to homepage.

    Now everything is working good. But I want to use pagination for this section. Here is my code block;

    <?php
    global $wp_query;
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $port_args = array(
            'post_type'     => 'portfolio',
            'posts_per_page'  => 3,
            'post_status'     => 'publish',
            'paged'       => $paged
    );
    $wp_port_query = new WP_Query($port_args);
    
    if( have_posts() ) :
        while ( $wp_port_query->have_posts() ) : $wp_port_query->the_post();
            ?>
            <li class="col-lg-4 col-sm-4 view item <?php $terms = get_the_terms( get_the_ID(), 'portfolio_filter' ); ?><?php if($terms) : foreach ($terms as $term) { echo $term->slug.' '; } endif; ?>">
    
                <?php the_post_thumbnail("portfolio-image"); ?>
    
            </li>
            <?php
        endwhile;
    endif;
    
    echo '<nav>';
    echo  '<div>'.get_next_posts_link('Older', $wp_port_query->max_num_pages).'</div>'; //Older Link using max_num_pages
    echo  '<div>'.get_previous_posts_link('Newer', $wp_port_query->max_num_pages).'</div>'; //Newer Link using max_num_pages
    echo "</nav>";
    
    wp_reset_query();
    ?>

    When I click the Older pagination button it’s going to ?paged=2 but it’s not working it shows same posts again. If I use the page template and open the themename/page_id=82 directly it’s working. And url looking like this ?page_id=82&paged=2 now I’m thinking I missing page id on section. How can I fix this and work it in homepage template section. If it’s not working how can I add the page_id in get_next_posts_link . It’s looking like this now ?paged=2 and I want to change it like this ?page_id=82&paged=2. Page id is coming automaticly from page. How can I do this?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Custom post pagination’ is closed to new replies.