Last active
September 10, 2019 14:16
-
-
Save nicomollet/ac40244eaa3b50b81cce0ca2a5aedd00 to your computer and use it in GitHub Desktop.
Elementor: Force posts per page number for posts widget on Category Pages
This file contains hidden or 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
<?php | |
/** | |
* Elementor: Force posts per page number for posts widget on Category Pages | |
* | |
* @param $query | |
*/ | |
function elementor_category_posts_per_page( $query ) { | |
$category_id_or_slug = 'myslug'; | |
$posts_per_page = 6; | |
if( !is_admin() && $query->is_main_query() && is_category( $category_id_or_slug ) ) { | |
$query->set('posts_per_page', $posts_per_page); | |
} | |
} | |
add_action( 'pre_get_posts', 'elementor_category_posts_per_page' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment