Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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%).

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.

share|improve this question
    
NOTE: You cannot use paging when using an offset, the built in paging system sets the offset, when you set the offset yourself you mess with the internal calculations that work out the result set to return. If you want to use the offset parameter you'll have to do paging and offset calculations yourself(aswell as build the paging links). –  t31os Aug 10 '11 at 12:06
    
How have you registered your post type? –  Alex Older Aug 10 '11 at 14:26
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.