When using the WordPress plugin Events Manager with Redis Cache you’ll find that your taxonomies don’t update as expected due to Events Manager not clearing the cache during it’s save function. To fix this find em-taxonomy-admin.php
and then at the end of the save
method add wp_cash_flush();
before the final closing bracket. The final save
method should look like this.
public static function save( $term_id, $tt_id ){
global $wpdb;
if (!$term_id) return;
if( !empty($_POST['term_color']) ){
//get results and save/update
$color = sanitize_hex_color($_POST['term_color']);
if( $color ){
$prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='". self::$option_name ."-bgcolor'");
if( count($prev_settings) > 0 ){
$wpdb->update(EM_META_TABLE, array('object_id' => $term_id, 'meta_value' => $color), array('object_id' => $term_id, 'meta_key' => self::$option_name .'-bgcolor'));
}else{
$wpdb->insert(EM_META_TABLE, array('object_id' => $term_id, 'meta_key' => self::$option_name .'-bgcolor', 'meta_value' => $color));
}
}
}
if( !empty($_POST['term_image']) ){
//get results and save/update
$term_image = esc_url_raw($_POST['term_image']);
$prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='". self::$option_name ."-image'");
if( count($prev_settings) > 0 ){
$wpdb->update(EM_META_TABLE, array('object_id' => $term_id, 'meta_value' => $term_image), array('object_id' => $term_id, 'meta_key' => self::$option_name .'-image'));
}else{
$wpdb->insert(EM_META_TABLE, array('object_id' => $term_id, 'meta_key' => self::$option_name .'-image', 'meta_value' => $term_image));
}
if( !empty($_POST['term_image_id']) && is_numeric($_POST['term_image_id']) ){
//get results and save/update
$term_image_id = absint($_POST['term_image_id']);
$prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='". self::$option_name ."-image-id'");
if( count($prev_settings) > 0 ){
$wpdb->update(EM_META_TABLE, array('object_id' => $term_id, 'meta_value' => $term_image_id), array('object_id' => $term_id, 'meta_key'=> self::$option_name .'-image-id'));
}else{
$wpdb->insert(EM_META_TABLE, array('object_id' => $term_id, 'meta_key'=> self::$option_name .'-image-id', 'meta_value' => $term_image_id));
}
}
}else{
//check if an image exists, if so remove association
$prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='". self::$option_name ."-image'");
if( count($prev_settings) > 0 ){
$wpdb->delete(EM_META_TABLE, array('object_id' => $term_id, 'meta_key' => self::$option_name .'-image'));
$wpdb->delete(EM_META_TABLE, array('object_id' => $term_id, 'meta_key' => self::$option_name .'-image-id'));
}
}
wp_cache_flush(); // fixing cache clearing error
}
I reported this bug over a year ago and have reached out to the developer in numerous ways but the fix hasn’t been applied as of the most recent release 2 days ago. While the plugin is great, it seems that the developer doesn’t check the forums at all so I’ll have to keep patching the plugin on update, which is a huge waste of my time.
Maybe this blog post will reach them.