Title: Custom Post Type Pagination
Last modified: August 20, 2016

---

# Custom Post Type Pagination

 *  [craiggrella](https://wordpress.org/support/users/craiggrella/)
 * (@craiggrella)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/custom-post-type-pagination-2/)
 * I’m trying to get pagination to work correctly with a video thumbnail gallery
   based on a custom post type called “videos.”
 * I am using a custom loop to pull in the videos and thumbnails and wp pagenavi
   plugin.
    I can get the videos to display correctly OR the pagenavi to display
   correctly, but not both at the same time.
 * Any help would really be appreciated.
 * Here’s the code I’m using with thesis theme:
 *     ```
       function thesis_video_gallery() { 
   
       $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
       query_posts( array( 'post_type' => 'videos', 'posts_per_page' => 12, 'caller_get_posts' => 1, 'paged' => $paged ) );
   
       	if ( is_page('scleroderma-video-gallery') && !is_single() ){
   
       	global $post;
       	$args = (array( 'post_type' => 'videos'));
       	$loop = new WP_Query( $args );
       	while ( $loop->have_posts() ) : $loop->the_post();
       	$post_image = thesis_post_image_info('thumb');
   
       ?>	<div id="vid-gallery">
       		<div class="vid-thumb">
       			<a>ID, $key, true); ?>" rel="shadowbox" title="<?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, 'youtube_thumb', true) ?>" alt="<?php the_title(); ?>"></a></div>
       		<div class="vid-title">
       			<h2><a>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
       		</div>
   
       	</div>
   
       <?php	endwhile;
   
       	if(function_exists('wp_pagenavi')) wp_pagenavi(); wp_reset_query();
       	}
       }
   
       add_action('thesis_hook_after_content', 'thesis_video_gallery');
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [craiggrella](https://wordpress.org/support/users/craiggrella/)
 * (@craiggrella)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/custom-post-type-pagination-2/#post-2649084)
 * Ok,
 * I moved the query under my if statement and got it to work:
    here’s the final
   code I used:
 *     ```
       function thesis_video_gallery() { 
   
       	if ( is_page('scleroderma-video-gallery') && !is_single() ){
   
       	global $post;
       	$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
       	$args = (array( 'post_type' => 'videos', 'posts_per_page' => 12, 'caller_get_posts' => 1, 'paged' => $paged ));
       	$loop = new WP_Query( $args );
       	while ( $loop->have_posts() ) : $loop->the_post();
       	$post_image = thesis_post_image_info('thumb');
   
       	query_posts( array( 'post_type' => 'videos', 'posts_per_page' => 12, 'caller_get_posts' => 1, 'paged' => $paged ) );
   
       ?>	<div id="vid-gallery">
       		<div class="vid-thumb">
       			<a href="<?php $key="lightbox_url"; echo get_post_meta($post->ID, $key, true); ?>" rel="shadowbox" title="<?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, 'youtube_thumb', true) ?>" alt="<?php the_title(); ?>"></a></div>
       		<div class="vid-title">
       			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
       		</div>
   
       	</div>
   
       <?php	endwhile;
   
       	if(function_exists('wp_pagenavi')) wp_pagenavi(); wp_reset_query();
       	}
       }
   
       add_action('thesis_hook_after_content', 'thesis_video_gallery');
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Custom Post Type Pagination’ is closed to new replies.

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [navigation](https://wordpress.org/support/topic-tag/navigation/)
 * [page navi](https://wordpress.org/support/topic-tag/page-navi/)
 * [Thesis](https://wordpress.org/support/topic-tag/thesis/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [craiggrella](https://wordpress.org/support/users/craiggrella/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/custom-post-type-pagination-2/#post-2649084)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
