I'm trying to take 12 posts per a page, but it displays only 4 posts.
Has anyone encountered this problem?
Current Code
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 12,
'order' => 'DESC',
'paged' => $paged,
);
$lists = new WP_Query($args);
echo $lists->post_count; // this outputs 12!
<ul>
<?php if ($lists->have_posts()) : ?>
<?php while ($lists->have_posts()) : $lists->the_post(); ?>
<li>
<div>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
</li>
<?php endwhile; ?>
<?php endif;
wp_reset_postdata(); ?>
</ul>
My Answer:
't work in WordPress?
There could be several reasons why the posts_per_page parameter is not working in WordPress. Some possible reasons include:
1. Incorrect syntax: Make sure that you are using the correct syntax for the posts_per_page parameter in your query. It should be set as a key-value pair in the query arguments array.
2. Theme or plugin conflict: Sometimes, a theme or plugin may be overriding the posts_per_page parameter in your query. Try deactivating any plugins or switching to a default theme to see if the issue persists.
3. Custom query modifications: If you are using a custom query to display posts, make sure that you are correctly setting the posts_per_page parameter in your query.
4. Caching issues: If you are using a caching plugin, it may be caching the query results and ignoring the posts_per_page parameter. Try clearing the cache or disabling the caching plugin to see if that resolves the issue.
5. Database corruption: In rare cases, database corruption or issues with the WordPress installation may cause the posts_per_page parameter to not work as expected. Try repairing the database or reinstalling WordPress to see if that resolves the issue.
Rate this post
3 of 5 based on 4087 votesComments