 
  
   
  
  <?php $portfolio_posts = new WP_Query( [
                                'post_type'      => 'portfolio',
                                'posts_per_page' => - 1,
                            ] ); ?>
                            
                            <?php $increment = 1; ?>
                            
                            <?php if ( $portfolio_posts->have_posts() ) : while( $portfolio_posts->have_posts() ) : $portfolio_posts->the_post(); ?>
                            <?php var_dump($increment); ?>
                            <?php if ( $increment % 2 !== 0 ): ?>
                            <div class="portfolio-item-wrap">
                                <?php endif ?>
                                <div class="portfolio-item">
                                    <a class="overlay" href="<?php the_field( 'link_to_project' ); ?>" target="_blank">
                                        <span class="portfolio-content">
                                            <h1><?php the_title(); ?></h1>
                                            <h4><?php the_content(); ?></h4>
                                        </span>
                                    </a>
                                    <?php the_post_thumbnail( 'small' ); ?>
                                </div>
                                
                                <?php if ( $increment % 2 === 0 ): ?>
                            </div>
                            <?php endif ?>
                            <?php ++$increment; ?>
                            
                            <?php endwhile; ?> 
  
   
  
   
  
   
  
   
  
   
  
   
  
   
  
  
Там в блоке портфолио, если 2 работы, то все в порядке, если одна, то отображается неправильно.