103 posts
  • 2 Years of Membership
  • Author Level 2
  • Collector Level 2
  • Exclusive Author
QUAL
says

My code (below) adds an action to increase the default, posts_per_page for all queries. Is this against the following rule? Should I use this rule only for home page?

Themes are not permitted to add options that define the number of posts to show on archive or category pages via a global setting.
My code: function my_function_to_increase_limit( $query ) { $query->set( 'posts_per_page', 24 ); } add_action(“pre_get_posts”, "my_function_to_increase_limit");
3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 more
sevenspark
Moderator
says

Using pre_get_posts isn’t an issue, but you’re not allowed to adjust the posts_per_page that way because there is already a core WordPress setting to do that (Reading > Blog pages show at most). So your code will override the standard functionality, and that’s why it’s not allowed.

103 posts
  • 2 Years of Membership
  • Author Level 2
  • Collector Level 2
  • Exclusive Author
QUAL
says

Using pre_get_posts isn’t an issue, but you’re not allowed to adjust the posts_per_page that way because there is already a core WordPress setting to do that (Reading > Blog pages show at most). So your code will override the standard functionality, and that’s why it’s not allowed.
OK thanks, than I should use get_posts to define my limit. http://codex.wordpress.org/Template_Tags/get_posts
3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 more
sevenspark
Moderator
says

If you’re running a secondary query, then yes – you can use get_posts()

If you’re modifying the main query, then you should use the pre_get_posts. You just shouldn’t make modifications that will prevent core settings from working.

103 posts
  • 2 Years of Membership
  • Author Level 2
  • Collector Level 2
  • Exclusive Author
QUAL
says

If you’re running a secondary query, then yes – you can use get_posts() If you’re modifying the main query, then you should use the pre_get_posts. You just shouldn’t make modifications that will prevent core settings from working.

Thanks! I have a final question. (sorry for too many questions)

I get all the posts with WP_Query for all of index, category, archive… Because I need more than 10 posts in my design. Is this against the following rule:

Themes are not permitted to add options that define the number of posts to show on archive or category pages via a global setting.
by
by
by
by
by
by