• Hello,

    I am trying to add pagination to a Custom Post Type that I have called casestudies. So far I have created the CPT and some sample content. In functions.php, I created a shortcode as follows which shows all the posts:

    function show_custom_casestudy_all_pagination_callbk(){
        ob_start();
        global $post;
        $args = array(
                      'post_type' => 'casestudies',
    				  'post_status' => 'publish',
    				  'posts_per_page' => -1,
    				  'caller_get_posts'=> 1
                      );
    
        $query = new WP_Query($args);
    
        if($query->have_posts()):while($query->have_posts()):$query->the_post();
    
        echo '<div class="casestudy-container">';
    
        echo '<div class="single-casestudy">';
    
        echo '<h2 class="case-title">'.get_the_title().'</h2>';
    
        $odmname = get_field('odm_name',$post->ID);
    
        if( $odmname ) {
    
        echo '<p class="odm-name"> ODM Name :- '.$odmname.'</p>';
    
        }
    
        $odmemail = get_field('odm_email',$post->ID);
    
        if( $odmemail ) {
    
        echo '<p class="odm-mail"> ODM Mail :- '.$odmemail.'</p>';
    
        }
    
        echo '<div>';
    
        echo '</div>';
    
        endwhile;endif;
    
        wp_reset_postdata();
    
        return ob_get_clean();
    
    }

    How do I get it to now show only 2 posts at a time and then put pagination / pager at the bottom?

    Thanks….

  • The topic ‘Custom Post Types pagination’ is closed to new replies.