'Why posts_per_page doesnt work? (wordpress)
I'm attempting to avoid querying all of my site's posts, as there are many and the site becomes slow when this script runs.
I've read every similar question and done the following without success:
- using
showpostsparameter - adding
wp_reset_query(); - passing args as an array
but nothing seems to work, it always returns all the posts.
$the_query = new WP_Query( 'posts_per_page=8' );
$blogs = [];
while ($the_query -> have_posts()): $the_query -> the_post();
$post_categories = [];
foreach (get_the_category($post->ID) as $key => $cat) {
if($cat->term_id == 2) continue;
array_push($post_categories,
"<a href='". get_category_link($cat->term_id) ."'>{$cat->name}</a>"
);
}
$blogs[] = [
'title' => get_the_title($post->ID),
'abstract' => substr(wp_strip_all_tags($post->post_content), 0, 80)
];
endwhile;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
