Posts number in a loop that uses term and date


Im using this method to get some posts with a certain term in front of others.
But, as Im also using pagination, term-a posts are being divided between all pages, so sometimes the number of term-a posts show in one page will differ, acourding to the total number of posts.
I want to know if its possible to display 5 of the posts from term-a.

$post_type_posts = []; //change to $post_type_posts = array(); for pre 5.4
$other_posts = []; //change to $other_posts = array(); for pre 5.4

if(have_posts()) {
    while(have_posts()) {

       if( has_term( 'term-a', 'tax' ) ) {
          $post_type_posts[] = get_the_title();
          $other_posts[] = get_the_title();

$new_loop = array_merge($post_type_posts, $other_posts);

foreach ($new_loop as $loop) {
   var_dump( $loop );

Fernando Souza 1 month 2021-04-08T06:07:52-05:00 0 Answers 0 views 0

Leave an answer