Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ulziibat-n/0d171bd24384a2b420c76e691c5a646b to your computer and use it in GitHub Desktop.
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
<?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