Skip Navigation

[Resolved] Illegal offset type warning

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by nathanH 5 years, 10 months ago.

Author
Posts
#1201694
Screenshot 2019-02-18 at 11.14.08.png

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.

#1201703

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.