Posts per page option not working
-
I have a strange option with the number of posts displayed on the author page
https://fit-life.info/author/andreas_ioannidis/
iget always 10 posts even if i change the option to 12 ont he settings and even if i use this code on functions.phpfunction limit_change_posts_archive($query){ $query->set('posts_per_page', 12); return; } add_filter('pre_get_posts', 'limit_change_posts_archive', 1);
i cant understand why this is happening. im sure i have more than 10 posts of this author
Viewing 3 replies - 1 through 3 (of 3 total)
-
also this is the way im showing the posts:
function latest_posts_mansory(){ $output = ''; $this_category = get_category( get_query_var( 'cat' ) ); $cat_id = $this_category->cat_ID; $args = array( 'post_status' => 'publish' ); $args['showposts'] = 12; if (is_author()) { $args['author'] = get_the_author_meta('ID'); } else { $args['category'] = $cat_id; } $recent_posts = wp_get_recent_posts( $args ); $num_posts = count($recent_posts); $curtitle = get_category_parents( get_query_var('cat') , false , ' - ' ); if (!is_author()) { $output .= '<div class="section_title underline" id="section-title-5314721809a17" style="border-color: #dddddd;"><span class="title">'.substr($curtitle , 0, -2).'</span></div>'; } else { $output .= '<div class="section_title underline" id="section-title-5314721809a17" style="border-color: #dddddd;"><span class="title">Προβολ? ?ρθρων</span></div>'; } $output .= '<div class="post_list masonry isotope" style="display: block; position: relative; overflow: hidden; height:494px;">'; $j=0; if ($num_posts == 0 && is_author()){ $output .='<div class="no results" style="text-align:center;position: inherit;" align="center"><h5 ALIGN="CENTER">Δεν υπ?ρχουν ?ρθρα απ\'τον συγκεκριμ?νο συντ?κτη</h5></div>'; }elseif ($num_posts == 0){ $output .='<div class="no results" style="text-align:center;position: inherit;" align="center"><h5 ALIGN="CENTER">Δεν υπ?ρχουν ?ρθρα σε αυτ?ν την κατηγορ?α</h5></div>'; }else{ for ($i=0; $i<$num_posts; $i++){ $recent_posts_usage = $recent_posts[$i]['ID']; $this_ID = $recent_posts[$i]['ID']; $post_class = join(" ", get_post_class('', $this_ID)); $this_title = get_the_title ($this_ID); $category = get_the_category ($this_ID); $this_category = $category[0]->cat_name; $this_thumb = get_the_post_thumbnail( $this_ID, 'medium'); $this_permalink = get_permalink($this_ID); $page_data = get_page( $this_ID ); $excerpt = T2T_Toolkit::truncate_string(apply_filters('the_content', strip_tags($page_data->post_content)), 200); $output .= '<div class="callout_box with_post one_fourth isotope-item'; if($j==3){ $output .= ' column_last'; $j=0; } else { $j++; } $output .= '" style="position: absolute; left: 0px; top: 0px; -webkit-transform: translate3d(476px, 0px, 0px);">'; $output .= '<article id="post-'.$this_ID.'" class="'.$post_class.'">'; $output .= ' <a href="'.$this_permalink.'"> '.$this_thumb.' </a>'; $output .= '<div class="callout_box_content">'; $output .= '<h3> <a href="'.$this_permalink.'">'.$this_title.' </a></h3>'; $output .= $excerpt; $output .='</div>'; $output .='</div>'; $output .='</article>'; } } $output .='</div>'; return $output; } add_shortcode('show_latest_posts_mansory', 'latest_posts_mansory');
seems to be fixed
– was it caused by your cache plugin?no it was the wp_get_recent_posts command. i should never use those again and i will use only the main functions and queries like WP_Query wordpress usually use.
This is the new function that is working:$output = ''; $this_category = get_category( get_query_var( 'cat' ) ); $cat_id = $this_category->cat_ID; $args = array( 'post_status' => 'publish' ); if (is_author()) { $args['author'] = get_the_author_meta('ID'); } else { $args['cat'] = $cat_id; } $args['paged'] = get_query_var( 'paged' ); $curtitle = get_category_parents( get_query_var('cat') , false , ' - ' ); //echo headers if (!is_author()) { $output .= '<div class="section_title underline" id="section-title-5314721809a17" style="border-color: #dddddd;"><span class="title">'.substr($curtitle , 0, -2).'</span></div>'; } else { $output .= '<div class="section_title underline" id="section-title-5314721809a17" style="border-color: #dddddd;"><span class="title">Προβολ? ?ρθρων</span></div>'; } $output .= '<div class="post_list masonry isotope" style="display: block; position: relative; overflow: hidden; height:494px;">'; $recent_posts = new WP_Query( $args ); if ( $recent_posts->have_posts() ) { while ( $recent_posts->have_posts() ) { $recent_posts->the_post(); // do stuff $num_posts = count($recent_posts); //get ID,title,permalink etc $j=0; $recent_posts_usage = get_the_ID(); $this_ID = get_the_ID(); $post_class = join(" ", get_post_class('', $this_ID)); $this_title = get_the_title (); $category = get_the_category (); $this_category = $category[0]->cat_name; $this_thumb = get_the_post_thumbnail( $this_ID, 'medium'); $this_permalink = get_the_permalink(); $page_data = get_page( $this_ID ); $excerpt = T2T_Toolkit::truncate_string(apply_filters('the_content', strip_tags($page_data->post_content)), 200); //echo content $output .= '<div class="callout_box with_post one_fourth isotope-item'; if($j==3){ $output .= ' column_last'; $j=0; } else { $j++; } $output .= '" style="position: absolute; left: 0px; top: 0px; -webkit-transform: translate3d(476px, 0px, 0px);">'; $output .= '<article id="post-'.$this_ID.'" class="'.$post_class.'">'; $output .= ' <a href="'.$this_permalink.'"> '.$this_thumb.' </a>'; $output .= '<div class="callout_box_content">'; $output .= '<h3> <a href="'.$this_permalink.'">'.$this_title.' </a></h3>'; $output .= $excerpt; $output .='</div>'; $output .='</article>'; $output .='</div>'; } wp_reset_postdata(); } else { // none were found if (is_author()){ $output .='<div class="no results" style="text-align:center;position: inherit;" align="center"><h5 ALIGN="CENTER">Δεν υπ?ρχουν ?ρθρα απ\'τον συγκεκριμ?νο συντ?κτη</h5></div>'; }else{ $output .='<div class="no results" style="text-align:center;position: inherit;" align="center"><h5 ALIGN="CENTER">Δεν υπ?ρχουν ?ρθρα σε αυτ?ν την κατηγορ?α</h5></div>'; } } $output .='</div>'; return $output;
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Posts per page option not working’ is closed to new replies.