# Problem with PHP code in latest PHP version

**URL:** <https://www.phphelp.com/t/problem-with-php-code-in-latest-php-version/35433>\
**Category:** Beginners - Learning PHP\
**Created:** [May 8, 2023, 9:49am UTC](https://www.phphelp.com/t/problem-with-php-code-in-latest-php-version/35433 "2023-05-08T09:49:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cocodoobster](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cocodoobster](https://www.phphelp.com/u/cocodoobster)\
**Post date:** [May 8, 2023, 9:49am UTC](https://www.phphelp.com/t/problem-with-php-code-in-latest-php-version/35433/1 "2023-05-08T09:49:37Z")

</div>

I am helping out a friend on his website and there are problems upgrading to the latest version of PHP… I feel like the problem is in the code below… I can’t seem to work it out. Any suggestions? Thank you in advance!

```auto
 <?php
                $args = array(
                    'category_name' => news,
                );
                $newsQuery = new WP_Query($args);
                if ($newsQuery->have_posts()) : while ($newsQuery->have_posts()) : $newsQuery->the_post();
                ?>

                    <div class="col-lg-4 col-md-6 mb-3">
                        <div class="card">
                            <div class="card-img"
                                 style="background-image: url('<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>');"></div>
                            <div class="card-body">
                                <h5 class="card-title"><?php the_title() ?></h5>
                                <p class="card-text"><?php echo excerpt(10) ?></p>
                                <a href="<?php the_permalink() ?>" class="btn btn-primary">
                                    View more
                                </a>
                            </div>
                        </div>
                    </div>

                <?php endwhile; else : ?>

                    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>

                <?php endif; ?>
```

---

<div class="post-metadata">

**Author:** ![katsry](https://www.phphelp.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@katsry](https://www.phphelp.com/u/katsry)\
**Post date:** [August 5, 2023, 5:39pm UTC](https://www.phphelp.com/t/problem-with-php-code-in-latest-php-version/35433/2 "2023-08-05T17:39:47Z")

</div>

The potential issue might be with the function `excerpt(10)`. WordPress does not have a native `excerpt()` function that takes an argument like that. If this is a custom function defined in the theme or a plugin, you would need to make sure that function is defined and working properly. If you want to use WordPress’s native excerpt functionality, you might replace `<?php echo excerpt(10) ?>` with `<?php the_excerpt(); ?>`.

So, the corrected code looks like this:

```auto
<?php
$args = array(
    'category_name' => 'news',
);
$newsQuery = new WP_Query($args);
if ($newsQuery->have_posts()) : while ($newsQuery->have_posts()) : $newsQuery->the_post();
?>

    <div class="col-lg-4 col-md-6 mb-3">
        <div class="card">
            <div class="card-img"
                 style="background-image: url('<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>');"></div>
            <div class="card-body">
                <h5 class="card-title"><?php the_title() ?></h5>
                <p class="card-text"><?php the_excerpt(); ?></p>
                <a href="<?php the_permalink() ?>" class="btn btn-primary">
                    View more
                </a>
            </div>
        </div>
    </div>

<?php endwhile; else : ?>

    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>

<?php endif; ?>

```
