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
Have you googled for the fix?
`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.