managed wordpress hosting

Pagination for Custom Post Types in WordPress


On 12-15-2013 code, wordpress

Custom Post Types in WordPress are a great way to expand on custom WordPress development. Once you have all the custom post type in your functions.php file, usually you call a custom query in your template page for your custom post type.

When doing pagination for a custom post type in WordPress

One thing to keep in mind is you need to add pagination in your query parameter. By default it doesn’t actually go to the next “page”. So use this code for adding the pagination function to your custom post type.

$paged

So a sample would be:

query_posts('post_type=your_custom_post_type_name&posts_per_page=10'.'&paged='.$paged);

We are querying our custom post type, with 10 posts per page, and lastly we tack on the paged feature. This makes the pagination work. Without it, when clicked on next page it takes you back to the first page. This works with pagination plugins as well. Well at least the one I have used.