72 posts
  • Has been part of the Envato Community for over 1 year
  • Has collected 10+ items on Envato Market
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");
3434 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 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.

72 posts
  • Has been part of the Envato Community for over 1 year
  • Has collected 10+ items on Envato Market
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
3434 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 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.

72 posts
  • Has been part of the Envato Community for over 1 year
  • Has collected 10+ items on Envato Market
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