I would like to paginate this query but I get no links for pagination at the end of the list of posts fetched. How can I fix it?
For further information, this query is run via a shortcode, so it might be placed on another page or post. So it might be the case that the post is already paginated, but within that post we then find this code that is getting some posts from the custom post type, and they need to be paginated as well.
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
// Query to get all test items for display
$test_items = new WP_Query( array(
'post_type' => 'myplugin_test_item',
'posts_per_page' => $settings['test_limit'],
'orderby' => 'meta_value',
'meta_key' => 'myplugin_item_date',
'order' => 'DESC',
'paged' => $paged,
) );
// Globalize $wp_query
global $wp_query;
// Swap-hack
$temp = $wp_query;
$wp_query = null;
$wp_query = $test_items;
if( $test_items->have_posts() ) {
while ( $test_items->have_posts() ) {
$test_items->the_post();
$permalink = get_post_meta( get_the_ID(), 'myplugin_item_permalink', true );
}
echo paginate_links();
wp_reset_postdata();
} else {
echo 'No test items found';
}
$wp_query = null;
$wp_query = $temp; // Reset
}
