Posts number in a loop that uses term and date

Question

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()) {
       the_post();

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

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

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

0
Fernando Souza 7 days 2021-04-08T06:07:52-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse