I'm getting an illegal offset type warning on a custom field in a custom search page I've created since upgrading to WordPress 5. The field and search work fine but I can't seem to get the warning to go away.
It's warning is regarding this block of code:
<div class="form-group">
<label>Age Group</label>
<?php
global $wpdb;
$ages_sql = $wpdb->get_col("SELECT DISTINCT(meta_value) FROM $wpdb->postmeta LEFT JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->postmeta.post_id WHERE meta_key = 'wpcf-q-age-groups' AND $wpdb->posts.post_status = 'publish'" );
$ages = array();
foreach($ages_sql as $age_sql){
$age = unserialize($age_sql);
foreach($age as $key => $a){
$ages[$a] = $a;
// $keys[$a] = $key;
}
}
// $ages = array_unique($ages);
sort($ages, SORT_NUMERIC);
// print_r($ages);
?>
<select id="age-groups" multiple class="chosen-select" name="age-groups">
<option selected="selected" value="0"></option>
<?php foreach($ages as $key => $age): ?>
<option <?php if(!empty($_SESSION['age_groups']) && in_array($age,$_SESSION['age_groups'])){echo 'selected';} ?> value="<?php echo $age; ?>"><?php echo $age; ?></option>
<?php endforeach; ?>
</select>
</div>
specifically line 30 which is this: $ages[$a] = $a;
The warning doesn't concern me - I just want to stop it from displaying 🙂
Here's an image of it on the page.
My issue is resolved now. Thank you!
I just added:
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);
To my wp-config file as functionality wasn't affected - it was just a warning - I'll try and find the cause later but I think it may have been the theme.