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.

Been trying to get this working all day but haven't had any luck...

I have a custom post type called 'news' and an archive template (archive-news.php), here I'd like to show 2 posts with pagination, which works fine, until I try to go to the 'next page' (/news/page/2) which returns an error 404.

Any idea how to fix this / what I'm doing wrong?

I've literally spent all day trying to find a solution to this by searching Google and the WordPress forms, I found lots of solutions, none of which have worked so far.

My custom post type function: http://pastebin.com/uG1L6YNu
My rewrite rules print: http://pastebin.com/jbaDANYr

share|improve this question
    
oh and also... My news-archive.php file: pastebin.com/vjcx77F7 –  Dale-Anthony Jul 10 '11 at 1:09

3 Answers 3

I founded the solution here > http://walrusinacanoe.com/web-development/742

Is elegant and functional>

add_action( 'parse_query','changept' );
function changept() {
    if( is_category() && !is_admin() )
        set_query_var( 'post_type', array( 'post', 'your_custom_type' ) );
    return;
}
share|improve this answer
    
This actually worked for me. The other solution (WP-Admin / Settings / Reading / 1) didn't work at all. Thanks for this! (hours wasted debugging and searching) –  TCattd Oct 14 at 22:03

This is now working for me... for those of you having the same issue it turns out all the code was correct.

The problem was WordPress is setup to show 10 posts per page by default which clashed with my query (limiting it to 2 posts) to fix the issue I changed the WordPress setting (Settings / Reading in the admin dashboard) to 1.

share|improve this answer
1  
This problem comes up all of the time. IMHO, custom post types are not regular posts, so there should be a separate posts_per_page query variable for each post type. Anyhoo, here's an answer that shows how to fiddle with the posts_per_page value on the fly without messing with setting in the admin: wordpress.stackexchange.com/questions/30757/… –  goto10 Feb 4 '12 at 0:41
    
That question by goto10 works like a charm and it's better if you still want to use the posts per page setting for other pages, I'm still curious on why this happens, this is the first time it happened to me I've been able to user posts_per_page like normal in before without it clashing with WP settings. –  javiervd Feb 23 '12 at 11:50
    
Thanks a ton for this info! Been pulling my hair out messing around with rewrite rules and everything else, and it turns out this is the issue. –  Chaser324 Aug 27 '12 at 19:11

You have probably tried this, but resetting the permalinks can solve this problem. Go to Settings->Permalinks and save the permalinks again.

share|improve this answer
    
Thanks, I did give this a go but the problem still remained. –  Dale-Anthony Jul 10 '11 at 9:51

protected by Community Apr 4 '13 at 15:45

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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