Answer the question
In order to leave comments, you need to log in
How to change the number of visible posts of a new post type in the WP admin?
Created fields in Redux for new post types "Reviews" and "News", which display the number of posts displayed on the archive pages of these posts. For "Reviews" in Redux, I chose to display 4 posts, for "News" - 2.
I wrote the code for this in functions.php.
function legal_advisory_posts_per_archivepage($query){
global $legal_advisory;
$posts_per_page_testy = -1;
$posts_per_page_news = -1;
if($legal_advisory['testimonial_posts']){$posts_per_page_testy = $legal_advisory['testimonial_posts'];}
if($legal_advisory['newspostsperpage']){$posts_per_page_news = $legal_advisory['newspostsperpage'];}
if(is_post_type_archive('testimonial')){
$query->set('posts_per_page', $posts_per_page_testy);
}
if(is_post_type_archive('news')){
$query->set('posts_per_page', $posts_per_page_news);
}
}
add_action('pre_get_posts','legal_advisory_posts_per_archivepage');
Answer the question
In order to leave comments, you need to log in
Wrap it up like this
if (!is_admin() && $query->is_main_query()) {
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question