Answer the question
In order to leave comments, you need to log in
How to set the number of posts to display for Wordpress custom post type archives?
Hello. I need to set, for a particular custom post type type, the number of posts to display for the Archives page (for all taxonomies of that custom post type type). On the Internet, I found the following code to insert into functions.php:
function custom_posts_per_page($query){
if(is_post_type_archive() || is_tax()){ //количество записей в пользовательстком типе записей и в пользовательских таксономиях
$query->set('posts_per_page',50);
}
}
add_action('pre_get_posts','custom_posts_per_page');
Answer the question
In order to leave comments, you need to log in
This is how it worked as it should:
function custom_posts_per_page($query){
if(!is_admin() && $query->is_main_query() && is_post_type_archive()){ //количество записей в пользовательстком типе записей
$query->set('posts_per_page',50);
}
if(!is_admin() && $query->is_main_query() && is_tax()){ //количество записей в пользовательстком типе записей в таксономиях
$query->set('posts_per_page',50);
}
}
add_action('pre_get_posts','custom_posts_per_page');
Try adding a condition to change the query
if ( is_post_type_archive( 'название кастомного типа products например' ) ) {
// ...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question