- Store your
new WP_Query()
in a variable - Globalize
$wp_query
- Move the
$wp_query
swap-hack to after yournew WP_Query()
generation - Pass the variable to
$wp_query
, not thenew WP_Query()
call itself.
e.g.
<?php
// Custom query args
$press_query_args = array(
'post_type' => 'press',
'orderby' => 'post_date',
//'showposts' => '10',
'posts_per_page' => $paged,
);
// Custom query
$press_query = new WP_Query( $press_query_args );
// Globalize $wp_query
global $wp_query;
// Swap-hack
$temp = $wp_query;
$wp_query= null;
$wp_query = $press_query;
// Output custom loop
while ($press_query->have_posts()) : $press_query->the_post();
// EVERYTHING FROM HERE BELOW SHOULD BE THE SAME,
// THOUGH I'VE CLEANED IT UP A BIT
// (MAINLY, REMOVING THE CLOSE/OPEN PHP TAG COMBOS)
// The following determines what the post format is and shows the correct file accordingly
$format = get_post_format();
get_template_part( '/lib/includes/post-formats/'.$format );
if($format == '')
get_template_part( '/lib/includes/post-formats/standard' );
endwhile;
if (function_exists("pagination")) {pagination($additional_loop->max_num_pages);}
$wp_query = null; $wp_query = $temp;
?>
EDIT
Re: your pagination/post-per-page issue:
Hi chip, thank you, but this produces some odd behavior, on the first page you see 10 articles and then pagination from pages 1-7, but on the second page you get the first two articles that appear on page 1 and the pagination numbering changes to go from 2-35
I suspect the problem lies here:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 10;
Couple with this array argument:
$wp_query->query(array(
'posts_per_page' => $paged,
));
What happens if you remove $paged
and the 'posts_per_page'
array argument?
ALSO:
The pagination (1-7 vs 2-35) issue is probably separate from the posts-per-page issue (though perhaps related). Try to use previous_posts_link()
and next_posts_link()
, just to isolate the posts-per-page issue.