{"id":16097,"date":"2012-04-05T03:09:33","date_gmt":"2012-04-05T07:09:33","guid":{"rendered":"http:\/\/www.templatemonster.com\/help\/?p=16097"},"modified":"2017-08-08T06:01:48","modified_gmt":"2017-08-08T10:01:48","slug":"wordpress-set-number-of-custom-posts-displayed","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/wordpress-set-number-of-custom-posts-displayed.html","title":{"rendered":"WordPress. Set number of custom posts displayed."},"content":{"rendered":"<p>\r\n<p>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 <strong>Appearance &gt; Reading<\/strong> section. <\/p>\r\n<p><a href=\"\/help\/wp-content\/uploads\/2012\/03\/wp-custom-posts-amount.jpg\"><img loading=\"lazy\" src=\"\/help\/wp-content\/uploads\/2012\/03\/wp-custom-posts-amount-300x194.jpg\" alt=\"\" title=\"wp-custom-posts-amount\" width=\"300\" height=\"194\" class=\"aligncenter size-medium wp-image-16098\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2012\/03\/wp-custom-posts-amount-300x194.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2012\/03\/wp-custom-posts-amount.jpg 748w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\r\n<div class=\"inline-banner\">\r\n<a href=\"https:\/\/www.templatemonster.com\/service-center\/\">\r\n<img src=\"\/help\/files\/banners\/inline\/Banner-3-(835-x100).jpg\" \/>\r\n<\/a>\r\n<\/div>\r\n<p>If the &quot;Blog pages show at most&quot; option doesn&#8217;t affect your posts please do the following:<\/p>\r\n<p>1. Access your WordPress installation directory<\/p>\r\n<p>2. Go to <strong>wp-content\/themes\/theme###<\/strong> folder<\/p>\r\n<p>3. Open <strong>functions.php<\/strong> file<\/p>\r\n<p>At the beginning of the document after the opening <strong>&lt;?php<\/strong> tag add the following:<\/p>\r\n<pre class=\"brush:php\">function iti_custom_posts_per_page($query)\r\n  {\r\n  switch ( $query-&gt;query_vars['post_type'] )\r\n  {\r\n  case 'your_custom_post_type_name': \/\/ Post Type named 'your_custom_post_type_name'\r\n  $query-&gt;query_vars['posts_per_page'] = X;\r\n  break;\r\n  default:\r\n  break;\r\n  }\r\n  return $query;\r\n  }\r\nif( !is_admin() )\r\n  {\r\n  add_filter( 'pre_get_posts', 'iti_custom_posts_per_page' );\r\n  }\r\n<\/pre>\r\n<p>Where replace <strong>&#8216;your_custom_post_type_name&#8217;<\/strong> with your custom post type name. And replace X for the variable <span class=\"brush:php\">$query-&gt;query_vars[&#8216;posts_per_page&#8217;]<\/span> with the amount of posts you want to display. For example:<\/p>\r\n<pre class=\"brush:php\">$query-&gt;query_vars['posts_per_page'] = 20;<\/pre>\r\n<\/p>\r\n<\/p>\r\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to set amount of custom posts in WordPress.<\/p>\n","protected":false},"author":2,"featured_media":16769,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[728],"tags":[789,592,2405],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/16097"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=16097"}],"version-history":[{"count":1,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/16097\/revisions"}],"predecessor-version":[{"id":82609,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/16097\/revisions\/82609"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media\/16769"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=16097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=16097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=16097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}