0

After having a Wordpress website moved from one environment to another (a test of migration from staging to dev to ensure no errors), everything works fine except for a While loop on custom blog templates. This loop work just fine on one environment, but after moving to another, the page stops working at the While loop.

Interestingly, when I remove the variables from the While, the page works, but of course my blog cards are blank except for the title. I'm at a loss as to what could be causing this to work fine in one place, and break in another. After going over it several times I can't seem to determine where an error might occur, or why.

 <div class="content-blog">
            <div class="loader"></div>

    <?php

    $count = 0;


    $args = array(
        'post_type' => 'blog',
        'orderby' => 'date',
        'posts_per_page' => 10,
        'post_status' => 'publish',
    );
    //our blog query
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) { ?>
<div class="band">
 <?php while ( $query->have_posts() ) : $query->the_post(); 


           $post_count = $query->post_count;
           $all_posts = $query->found_posts;
           $category = get_the_terms( $id, 'blog_category' ); 
           $count++;

        // Finds every 5th item and gives it item-1 string to add as class
           $size = $count % 5 === 0 ? 'item-1' : 'item-2';

        // Gets the post content so we can trim its size for a custom excerpt

           $content = get_the_content(); 

            // Trims the post content to 175 characthers                     
           $content_count = mb_strimwidth($content, 0, 175, '...');                          

          // If it is a large blog card add a few more characthers                       
            if ($count % 5 === 0) {
                $content_count = mb_strimwidth($content, 0, 225, '...');
            }       



     ?>
   <div id="post" class="<?php echo $size; ?>" data-offset="<?php echo $post_count; ?>" data-total="<?php echo $all_posts; ?>">
    <a href="<?php the_permalink(); ?>" class="card">
      <div class="thumb" style="background-image: url(<?php the_post_thumbnail_url();?>);"></div>
      <article class="<?php echo $category[0]->slug; ?>">
        <h1><?php the_title(); ?></h1>
           <p style="margin-top: 10px;">
              <?php echo $content_count; ?>
          </p>
        <span><?php echo $category[0]->name; ?></span>
      </article>
    </a>
  </div>


 <?php endwhile;
            wp_reset_postdata(); ?>
      <?php 
                                } ?>

</div>   

</div>  
DubVader
  • 1,032
  • 1
  • 6
  • 8
  • Do you have any PHP errors showing? I can see a trailing comma in the query after `'post_status' => 'publish',`. – Gavin Thomas Nov 02 '18 at 14:00
  • @GavinThomas A trailing comma in a PHP array is allowed. – disinfor Nov 02 '18 at 14:43
  • I didn't have access to alter config to turn on debugging but after my DevOps guys turned it on, we saw this thrown: Uncaught Error: Call to undefined function mb_strimwidth() in /var/www/wordpress/htdocs/wp-content/themes/bublup/blog-grid.php:292 Stack trace: #0 /var/www/wordpress/htdocs/wp-includes/template-loader.php(74): include() #1 /var/www/wordpress/htdocs/wp-blog-header.php(19): require_once('/var/www/wordpr...') #2 /var/www/wordpress/htdocs/index.php(17): require('/var/www/wordpr...') #3 {main} thrown in/var/www/wordpress/htdocs/wp-content/themes/bublup/blog-grid.phpon line292 – DubVader Nov 02 '18 at 14:50
  • He added some PHP extension/plug in, and now it works fine. But I'd like to know more about this if possible. The original environment that worked had PHP version 7.0.10. And the new environment has 7.0.32. I know enough PHP to have a conversation, but am still learning. So any information is valuable. – DubVader Nov 02 '18 at 14:50
  • `mb_strimwidth()` has been available since PHP4. The error means the Multibyte String extension was not installed on your new environment: https://stackoverflow.com/questions/14254943/mbstring-php-and-mb-strimwidth-issue – disinfor Nov 02 '18 at 15:58
  • @disinfor thank you. Makes sense. Much appreciated. – DubVader Nov 02 '18 at 18:50

1 Answers1

0

The problem stemmed from not having the Multibyte String Extension installed on the new environment. Thanks to @disinfor for the clarification of this issue.

DubVader
  • 1,032
  • 1
  • 6
  • 8