You can use WP_Query()
with paged
array key to pass the current page number:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'articles',
'posts_per_page' => 4,
'paged' => $paged
);
$articles = new WP_Query($args);
////////////////////////////////
$args = array(
'post_type' => 'news',
'posts_per_page' => 1,
'meta_query' => array(
array(
'key' => 'featured-news',
'value' => 'Yes',
'compare' => 'LIKE'
)
),
'paged' => $paged
);
$featured = new WP_Query($args);
////////////////////////////////
$args = array(
'post_type' => 'news',
'posts_per_page' => 2,
'meta_query' => array(
array(
'key' => 'featured-news',
'value' => 'No',
'compare' => 'LIKE'
)
),
'paged' => $paged
);
$non_featured = new WP_Query($args);
////////////////////////////////
$articles = objectToArray($articles); // objectToArray() function defines below
$featured = objectToArray($featured);
$non_featured = objectToArray($non_featured);
$all_posts = array_merge($featured, $articles, $non_featured);
?>
And because you are query-ing from 3 post types, pagination will fail, because it doesn’t know from which post type pagination should be based on!
You can use a manual pagination:
<?php
// $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if($paged > 1)
{
echo "<a href=\"".home_url("https://wordpress.stackexchange.com/")."/page/".($paged-1)."\">Previous page</a>";
}
echo "<a href=\"".home_url("https://wordpress.stackexchange.com/")."/page/".($paged+1)."\">Next page</a>";
?>
Maybe you want change the HREF attr to something else.
Which I forgot:
<?php
function objectToArray($d) {
if (is_object($d)) {
$d = get_object_vars($d);
}
if (is_array($d)) {
return array_map(__FUNCTION__, $d);
}
else {
return $d;
}
}
?>
WP_Query returns a stdClass Object, first you should convert it to an array like below:
<?php
$articles = objectToArray($articles);
$featured = objectToArray($featured);
$non_featured = objectToArray($non_featured);
?>
Then merging them. (updated code above)
Updated
Another handy way is merging stdClass Objects: https://stackoverflow.com/a/1953077/1906508