Answer the question
In order to leave comments, you need to log in
How to fix custom pre_get_posts error on 404 error?
Hello!
I installed pure WP, created the "books" category and wrote a function that displays the required number of entries in this category:
add_action( 'pre_get_posts', 'books_posts_per_page' );
function books_posts_per_page( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_category( 'books' ) ) {
$query->set( 'posts_per_page', '1' );
}
}
PHP Notice: Trying to get property 'term_id' of non-object in \wp-includes\class-wp-query.php on line 3718
PHP Notice: Trying to get property 'name' of non-object in \wp-includes\class-wp-query.php on line 3720
PHP Notice: Trying to get property 'slug' of non-object in \wp-includes\class-wp-query.php on line 3722
if ( $query->is_main_query() && is_tag() ) {
$query->set( 'posts_per_page', '1' );
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question