I'm trying to set posts_per_page
depending on what category is being shown.
The following code works.
function category_posts_per_page( $query )
{
if ( $query->is_main_query() && $query->is_category() && $query->is_category('books') ) {
$query->set('posts_per_page', 2);
}
}
add_action( 'pre_get_posts', 'category_posts_per_page' );
The problem:
I'm getting a php notice every 30 seconds in my debug log. No notices from visiting any posts, pages, categories or anything manually.
From debug.log:
[31-Oct-2018 10:18:46 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /var/www/html/wp-includes/class-wp-query.php on line 3502
[31-Oct-2018 10:18:46 UTC] PHP Notice: Trying to get property 'name' of non-object in /var/www/html/wp-includes/class-wp-query.php on line 3504
[31-Oct-2018 10:18:46 UTC] PHP Notice: Trying to get property 'slug' of non-object in /var/www/html/wp-includes/class-wp-query.php on line 3506
I've disabled all plugins, switched themes to a default one (and added the above code to functions.php).
How would I fix this? The code works and it's just a php notice, but it's a bit annoying... especially now in development and all notices are visible in debug.