62 posts
  • Bought between 10 and 49 items
  • Has been a member for 1-2 years
codepanels 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");
3424 posts
  • Football Contest Participant/Runner-up
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 100 and 499 items
  • Referred more than 2000 users
  • Has been a member for 4-5 years
+5 more
sevenspark Volunteer 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.

62 posts
  • Bought between 10 and 49 items
  • Has been a member for 1-2 years
codepanels 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
3424 posts
  • Football Contest Participant/Runner-up
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 100 and 499 items
  • Referred more than 2000 users
  • Has been a member for 4-5 years
+5 more
sevenspark Volunteer 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.

62 posts
  • Bought between 10 and 49 items
  • Has been a member for 1-2 years
codepanels 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