WordPress pagination break on homepage
-
I’m trying to get my homepage (home.php) to display a few posts thumbnails from a custom post type and to paginate through all of them.
Works OK for the first page, but when I try to get to the second page it doesn’t work.
if I add the following code to my functions.php
function homepage_custom( $query ) { if ($query->is_home() && $query->is_main_query()) { $query->set('post_type', array( 'custom' )); } } add_action( 'pre_get_posts', 'homepage_custom' );
I get no posts.
Trying again without the check for the main query
function homepage_custom( $query ) { if ($query->is_home()) { $query->set('post_type', array( 'custom' )); } } add_action( 'pre_get_posts', 'homepage_custom' );
I get the first posts (i’m displaying 16 on each page). When I go to the 2nd page the URL displays “localhost/page/2” but I see the same 16 posts. Reseting the permalinks to default gives me the same results.
If I try querying directly from the home.php with this:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array("post_type" => "custom", "paged" => $paged));
I see the first 16 and I get 404 on the 2nd page. Again, reseting the permalinks gives the same result.
I have 17 posts with this custom type.
Displaying 16 each page I get 2 pages seeing the same posts, and displaying 5 each page I get 4 pages seeing the same posts.
- The topic ‘WordPress pagination break on homepage’ is closed to new replies.