Created
May 10, 2022 14:41
-
-
Save thomasfromwood/2f6c391794252917721db3a851a017a8 to your computer and use it in GitHub Desktop.
Get unlimited posts on blog page despite of Settings > reading number #wordpress #blog #index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* :::::::::::::::::::::::::::::::::::: | |
* Unlimited posts (articles) on blog page | |
* ::::::::::::::::::::::::::::::::::::: | |
* Set the number of posts per page (post count) unlimited. Must be in functions.php */ | |
function modify_current_query_loop( $query ){ | |
//only if main query, you can also test with $query->is_tax('example-cpt-slug') or $query->is_archive() in the condition to be more accurate to your case | |
if( $query->is_main_query() ): | |
//set unlimited (-1) post count, pagination won't be displayed | |
$query->set('posts_per_page', -1); | |
// other modification settings : | |
// $query->set('order', 'ASC'); | |
// ... | |
// more settigns on https://developer.wordpress.org/reference/classes/wp_query/ | |
endif; | |
} | |
add_action('pre_get_posts', 'modify_current_query_loop'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment