wp query – posts_per_page in custom WP_Query does not override “Reading” settings?
I am trying to use WP_Query loop (below) to show all instances of a certain post type.
(This loop is not in the custom post type’s archive — it is in a template part that appears as a page section on two different pages of the site.)
posts_per_page set in the WP_query args, but the argument is ignored and the number of posts displayed is instead whatever number of blog posts is set in the WordPress “Reading” settings.
My (two-part) question is:
- How do I display all of the posts in this custom post type loop (while leaving the blog archive (index.php) set to display just 9 posts at a time)?
- What is the point of the
posts_per_pageargument existing and being available to set on individual queries, if it is overridden by the global setting in the dashboard GUI?? What does this argument even do if it can’t be used to set the number of posts displayed by an individual query?
Here is the code I am using for my query/loop:
<?php $args = array( 'posts_per_page' => -1, /* have also tried setting to 999 or using a variable -- is still ignored */ 'post_type' => 'department', 'status' => 'published' ); $serviceIcons = new WP_Query($args); if ($serviceIcons->have_posts() ) : // Loop department posts while ($serviceIcons->have_posts() ) : $serviceIcons->the_post(); get_template_part( 'template-parts/icon-grid-item' ); endwhile; endif; wp_reset_postdata(); ?>