Code with problems after PHP update from 7.4 to 8.1

This code was working fine with PHP 7.4:

@update_post_meta($post->ID, ‘discount-extra-site’, array_map( ‘strip_tags’, $_POST[‘discount-extra-site’] ) );
<option value=”<?php the_ID(); ?>” <?php if (is_array($sites_discounted) && in_array(get_the_ID(), $sites_discounted)) { echo “selected”; } ?>><?php the_title(); ?></option>

But the update_post_meta is not working so well after upgrade to PHP 8.1

I mean, it saves if I add some data, but if I want to remove it don’t let me…
I can change and add more data, but don’t let me remove it completely.

It gives me the following error:

Fatal error: Uncaught Error: array_map(): Argument #2 ($array) must be of type array, null given
in /home/username/public_html/wp-content/themes/wp-theme/functions.php on line 963

The line 963 is:

@update_post_meta($post->ID, ‘discount-extra-site’, array_map( ‘strip_tags’, $_POST[‘discount-extra-site’] ) );

Any idea how to fix this, please?

Thank you in advance

  1. `if ( ! empty( $_POST[‘discount-extra-site’] ) ) {`
    `update_post_meta( $post->ID, ‘discount-extra-site’, array_map( ‘strip_tags’, $_POST[‘discount-extra-site’] ) );`

    BTW… silencing errors with @ is almost always a code-smell.


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer