Categories

Featured templates

WordPress. Set number of custom posts displayed.

Chris Diaz April 5, 2012
Rating: 5.0/5. From 2 votes.
Please wait...

This tutorial shows how to set amount of custom posts in WordPress. Usually you should be able to set the amount of displayed posts in WordPress administration panel in Appearance > Reading section.

If the "Blog pages show at most" option doesn’t affect your posts please do the following:

1. Access your WordPress installation directory

2. Go to wp-content/themes/theme### folder

3. Open functions.php file

At the beginning of the document after the opening <?php tag add the following:

function iti_custom_posts_per_page($query)
  {
  switch ( $query->query_vars['post_type'] )
  {
  case 'your_custom_post_type_name': // Post Type named 'your_custom_post_type_name'
  $query->query_vars['posts_per_page'] = X;
  break;
  default:
  break;
  }
  return $query;
  }
if( !is_admin() )
  {
  add_filter( 'pre_get_posts', 'iti_custom_posts_per_page' );
  }

Where replace ‘your_custom_post_type_name’ with your custom post type name. And replace X for the variable $query->query_vars[‘posts_per_page’] with the amount of posts you want to display. For example:

$query->query_vars['posts_per_page'] = 20;

Buy Wordpress Templates
This entry was posted in WordPress Tutorials and tagged custom, post, WordPress. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket