The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WP posts per page on custom post type Reply To: WP posts per page on custom post type


Hey @steven,

Whenever you’re working with Custom Post Types and your query is not returning anything, but you feel you did everything correct… go and reset the permalinks by visiting Settings >> Permalinks. Select Default press Save Changes, then switch it back to Post Name and press Save Changes again.

In addition, you can modify your main query and just have your archive template return the results, no need for new WP_Query object.

The answer is in the link you posted. I’ve modified it to fit what you’re trying to do. If you need it to return all posts set the value to -1:

function set_posts_per_page_for_towns_cpt( $query ) {
  if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'towns' ) ) {
    $query->set( 'posts_per_page', '10' );
add_action( 'pre_get_posts', 'set_posts_per_page_for_towns_cpt' );

Place this code in your functions.php file.

Read more about pre_get_posts.

Hope that helps.