Archived topic
Not showing all posts
9 replies · Started by David on August 19, 2020
Hello
I have this website...
[In SITE URL]
Type password: glamping
I've added a custom post type called glamping. I have 14 listings, but only 10 are showing up on the page.
In Settings > Reading
I've changed... Blog pages show at most to 20.
Any ideas what is causing the others not to show.
Thanks
Dave
Hi there,
try including the Post Navigation on the CPT.
Tom provides a method to do that here:
https://generatepress.com/forums/topic/displaying-posts-navigation-on-cpts/#post-466321
Hi David
If I turn infinite scroll off in blog settings, I get the page navigation back.
How can I set the number of post to initial show on custom post types, and also use the infinite scroll?
Thanks
Dave
Ok thanks, I'll look into adding the infinite scroll, only other things is how do I change the option of how many posts show on the archive page?
You can use the pre_get_posts hook to change the posts_per_page like sp:
add_action( 'pre_get_posts', function( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( is_post_type_archive( 'my_custom_post_type' ) ) {
$query->set( 'posts_per_page', 9 );
}
} );
I added this to function.php but nothing changed
add_action( 'pre_get_posts', function( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( is_post_type_archive( 'glamping' ) ) {
$query->set( 'posts_per_page', 12 );
}
} );
Odd as thats a standard WP function.
Have you spoken with the Plugin author? as it seems to be doing things differently.
Yes all sorted thanks David
Glad to hear that.