0

So, I have a custom loop on my homepage:

  function homepage_loop(){

    $custom_loop_args = array( 'post_type' => array( 'post', 'review', 'video', 'feature' ) );
    $custom_loop_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

    $loop = new WP_Query( $custom_loop_args );

    // Pagination fix
    $wp_query   = NULL;
    $temp_query = $wp_query;
    $wp_query   = $loop;

    // Output custom query loop
    if ( $loop->have_posts() ) :
        while ( $loop->have_posts() ) :
            $loop->the_post();
            default_loop();
        endwhile;
    endif;
    // Reset postdata
    wp_reset_postdata();


     // Custom query loop pagination
     previous_posts_link( 'Older Posts' );
     next_posts_link( 'Newer Posts', $loop->max_num_pages );

     // Reset main query object
     $wp_query = NULL;
     $wp_query = $temp_query;

}
?>

Paging initially didn't work for this, until I added the following code into my functions.php file (found from an answer on a separate question on this site):

function my_post_count_queries( $query ) {
  if (!is_admin() && $query->is_main_query()){
    if(is_home()){
       $query->set('posts_per_page', 1);
    }
  }
}
add_action( 'pre_get_posts', 'my_post_count_queries' );

On my local version (running using Wamp) pagination works correctly.

However, on my live version (exactly the same code, exactly the same permalink structure) I get a 404 page when I try and hit the second page (/page/2/).

You can see it happening on my live site here - http://sevenoutoften.co.uk/page/2/

I've tried re-saving my permalink structure (no change), clearing the cache (no change). I've read a few articles saying that if you have a page slug the same name as a custom post type you can also run into issues but I'm not sure how I could go about checking this? I have no custom taxonomies, categories or pages with the same name as any of my custom post types.

I've been trying to find solutions for hours but am basically hitting my head against a brick wall. Any ideas? Thanks for helping!

0

The problem is with your permalinks, try changing to default, not to %postname%. If it still exist let me know further.

2
  • Yeah changing the permalinks to default doesn't fix the issue :( Any ideas? Nov 30 '17 at 14:19
  • your server is nginx or apache Dec 4 '17 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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