admin管理员组文章数量:1122832
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.)
I have 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_page
argument 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();
?>
本文标签: wp querypostsperpage in custom WPQuery does not override quotReadingquot settings
版权声明:本文标题:wp query - posts_per_page in custom WP_Query does not override "Reading" settings? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309216a1933935.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论