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


4 Answers 4


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.

  • 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/… Commented Feb 4, 2012 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. Commented Feb 23, 2012 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
    Commented Aug 27, 2012 at 19:11
  • It's 2019, and this answer is still valid! Amazing.
    – Cenlan
    Commented Dec 17, 2019 at 13:13
  • Thanks, very helpful. Commented Apr 19, 2022 at 20:19

I found a 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' ) );
  • 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
    Commented Oct 14, 2014 at 22:03
  • Many years later and this function solved the issue for me. 3 days of pulling my hair later! Thanks a million. Commented May 21 at 18:31

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

  • Thanks, I did give this a go but the problem still remained. Commented Jul 10, 2011 at 9:51

try this variant:

function custom_pre_get_posts( $query ) 
    if( $query->is_main_query() && !$query->is_feed() && !is_admin()) {
        $query->set( 'paged', str_replace( '/', '', get_query_var( 'page' ) ) );  

add_filter('request', 'custom_request');
function custom_request($query_string )
    if( isset( $query_string['page'] ) ) { 
        if( ''!=$query_string['page'] ) { 
            if( isset( $query_string['name'] ) ) { 
                unset( $query_string['name'] ); 
    } return $query_string; 
  • Can you explain your solution?
    – tehlivi
    Commented May 13, 2021 at 1:32
  • The code seems to show everything, it rebuilds the query string correctly. If any page is open, but it is not mistakenly reflected in the URL, rebuild and add the missing slug to the section.
    – ktscript
    Commented May 13, 2021 at 4:28

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