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


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.

| 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/… – Dave Romsey 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. – Javier Villanueva Feb 23 '12 at 11:50
  • 2
    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
  • It's 2019, and this answer is still valid! Amazing. – Cenlan Dec 17 '19 at 13:13

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

It 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' ) );
| improve this answer | |
  • 1
    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 '14 at 22:03

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

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

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