I've a custom page template where I want to query 2 posts from a post type and 1 post from another post type. I have it set up like this:
$paged = get_query_var('paged') ? get_query_var('paged') : 1; $articles = get_posts(array( 'post_type' => 'articles', 'numberposts' => 1, 'posts_per_page' => 1, 'paged' => $paged )); $news = get_posts(array( 'post_type' => 'news', 'numberposts' => 2, 'posts_per_page' => 2, 'paged' => $paged )); $all_posts = array_merge($articles, $news);
Then I do the loop:
<? foreach ($all_posts as $post): setup_postdata($post) ?> <? get_template_part('content') ?> <? endforeach ?>
And finally I add pagination. I tried WP-PageNavi as well as regular WordPress functions.
wp_pagenavi(); next_posts_link(); previous_posts_link();
When I go to the page I can see 3 posts as expected (1 article, 2 news) but there is no pagination. If I manually navigate to
/page/3, etc. it seems to work and show the next 3 posts but only the
previous_posts_link shows up, not the
next_posts_link or PageNavi.
The real world example is slightly more complicated and
WP_Query are not an option.
How to get pagination working properly?