Forked from nicomollet/elementor-category-posts-per-page.php
Created
September 10, 2019 14:16
-
-
Save ulziibat-n/0d171bd24384a2b420c76e691c5a646b to your computer and use it in GitHub Desktop.
Elementor: Force posts per page number for posts widget on Category Pages
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
<?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