Custom Post Type pagination – normal solutions aren’t helping

I have multiple custom post types and I need to be able to query them and page through them. This is the query I am trying:

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$offset = ( 10 * $paged ) - 10;
$args=array('paged'=>$paged, 'posts_per_page'=>10, 'post_type'=>'custom-post-type-name', 'offset' => $offset);
query_posts($args);

I’ve reset the permalinks and I’ve set the posts per page of WordPress to a lower number than what I’m querying and all I get is a 404 when I go to /page/2/ (my permalinks are set as /%postname%-%post_id%).

Read More

What’s most confusing though is on a separate page the following works:

SELECT *, IFNULL(SUM(vote),0) as total FROM wp_posts post LEFT JOIN wp_wdpv_post_votes votes ON votes.post_id = post.ID WHERE post.post_type = 'custom-post-type-name' AND post.post_status = 'publish' AND post.post_date > DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY post.ID ORDER BY total DESC LIMIT 0,3

but the following throws up the same 404 problems

SELECT *, IFNULL(SUM(vote),0) as total FROM wp_terms term JOIN wp_term_taxonomy taxonomy JOIN wp_term_relationships relationship JOIN wp_posts post LEFT JOIN wp_wdpv_post_votes votes ON votes.post_id = post.ID WHERE term.term_id = taxonomy.term_id AND relationship.term_taxonomy_id = taxonomy.term_taxonomy_id AND term.slug = 'games' AND taxonomy.taxonomy = 'category' AND post.ID = relationship.object_id AND post.post_type = 'custom-post-type-name' AND post.post_status = 'publish' AND post.post_date > DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY post.ID ORDER BY total DESC LIMIT 0,3

Any help on this would be gratefully received.

Related posts

Leave a Reply

1 comment

  1. This solution is a little tricky:

    • add this plugin WP Page Numbers.
    • change the WordPress Reading setting from admin panel from 10(which is the default) to 1 .(the point after making it 1 is to avoid page not found 404 error)

    • In the page you would like to show the custom posts we need to change the query by adding our options to the default query:

    <?php $newQuery='showposts=5&post_type=custom-post-type-name&page='.$paged.'&'.$query_string; ?>

    <?php query_posts($newQuery); ?>

    what we did here is we added our options without changing the default query.

    hope helpful.Please tell us in case that didn’t work with you.