Modify the number of WordPress posts or custom posts to be displayed on a custom archive page by adding this filter to your functions.php file in WordPress.
1 2 3 4 5 6 |
function mix_num_posts_for_archive($query) { if ($query->is_main_query() && $query->is_post_type_archive('your-custom-post-name') ) $query->set('posts_per_page', -1); } add_action('pre_get_posts', 'mix_num_posts_for_archive'); |
Change the number of “posts_per_page” to meet your specs, if you leave it at -1, it will show all the posts for this query.
To change it for category or tag archives…
1 2 3 4 5 6 |
function mix_num_posts_for_archive($query) { if ($query->is_main_query() && $query->is_category() || is_tag() ) $query->set('posts_per_page', -1); } add_action('pre_get_posts', 'mix_num_posts_for_archive'); |
Other conditional tags for archive pages
is_date() – When any date-based archive page is being displayed
is_year() – When a yearly archive is being displayed.
is_month() – When a monthly archive is being displayed.
is_day() – When a daily archive is being displayed.
is_time() – When an hourly, “minutely”, or “secondly” archive is being displayed.
is_search() – When a search result page archive is being displayed.
is_404() – When a page displays after an “HTTP 404: Not Found” error occurs.