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 migrate my web site from Joomla to WordPress. All are fine, I have create my Rewrites in htaccess to stop 404 from old URLs but I have problem with pagination.

In Joomla web site, I had 6 posts per page, but now in WordPress I need to display 10 posts per page. That's fine too.

The problem is that, in WordPress site now the very very last pages return 404 error because of the 10 posts per page I use now.

i.e.: In Joomla to get the 60th article I had to go on page 10, but now page 10 does not exists anymore, because In WordPress the very very last page now is the page 6. In that case, I will try to access the 7th, 8th, 9th or 10th page I get a 404 HTTP Error.

How can I fix that?

share|improve this question

closed as too localized by Wyck, t31os, Chip Bennett, Brady, kaiser Feb 16 '12 at 9:46

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 0 down vote accepted

The only way to really know if it's going to be a 404 is to let WordPress try to load it and check results before WP sends headers.

If you put this in your functions.php (not on a live site! use a dev mirror.), then visit a page that throws a 404, you can see the contents of the $wp_query object produced, is_404 will be true. By inspecting this you can determine what you want to do.

add_filter('template_redirect', 'wpse25745_inspect_query' );
function wpse25745_inspect_query() {
    global $wp_query;

    echo '<pre>';
    print_r($wp_query);
    echo '</pre>';
    die();

}

Following on that, you can redirect somewhere like this:

add_filter('template_redirect', 'wpse25745_inspect_query' );
function wpse25745_inspect_query() {
    global $wp_query;

    if( $wp_query->is_404 && $some_other_conditions_met == 'foo' ):
        wp_redirect( home_url(),301 );
        exit;
    endif;
}
share|improve this answer
    
That was realy very helpfull ! :) Thanks a lot about your answer –  Web Design Blog Aug 16 '11 at 7:52

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