Reputation: 748
I have this code:
query_posts(array(
'paged' => $paged,
'post_status' => 'publish',
'posts_per_page' => 6,
'cat' => $term_id,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post'
));
while (have_posts()) {
the_post();
...
}
But I still get 10 posts not only 6. Also get_query_var('posts_per_page', 1)
get me value 10 instead of 6. Why?
This is happening on the category.php page, on the homepage it is working correctly.
Upvotes: 0
Views: 1310
Reputation: 35
This one will work for you. modify direct global variable.
global $query_string;
query_posts("{$query_string}&posts_per_page=6");
while (have_posts()) {
the_post();
...
}
Upvotes: 0
Reputation: 714
You are still using the default query. Use this instead:
// The Query
$the_query = new WP_Query( array(
'paged' => $paged,
'post_status' => 'publish',
'posts_per_page' => 6,
'cat' => $term_id,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post'
));
// The Loop
if ( $the_query->have_posts() ) {
Upvotes: 1
Reputation: 496
Try this
$args = array (
'paged' => $paged,
'post_status' => 'publish',
'posts_per_page' => 6,
'cat' => $term_id,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post'
);
$query = new WP_Query($args);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
/* Your Code */
endwhile;
endif ;
Upvotes: 0