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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.