Until the release of PHP 8 I was able to replace "--" with a comma in a custom tag. using the following code.
if(!is_admin()){ // make sure the filters are only called in the frontend
$custom_taxonomy_type = 'winners_name'; // here goes your taxonomy type
function comma_taxonomy_filter($tag_arr){
global $custom_taxonomy_type;
$tag_arr_new = $tag_arr;
if($tag_arr->taxonomy == $custom_taxonomy_type && strpos($tag_arr->name, '--')){
$tag_arr_new->name = str_replace('--',', ',$tag_arr->name);
}
return $tag_arr_new;
}
add_filter('get_'.$custom_taxonomy_type, comma_taxonomy_filter);
function comma_taxonomies_filter($tags_arr){
$tags_arr_new = array();
foreach($tags_arr as $tag_arr){
$tags_arr_new[] = comma_taxonomy_filter($tag_arr);
}
return $tags_arr_new;
}
add_filter('get_the_taxonomies', comma_taxonomies_filter);
add_filter('get_terms', comma_taxonomies_filter);
add_filter('get_the_terms', comma_taxonomies_filter);
}
After the PHP update it's giving me the following error. PHP Fatal error: Uncaught Error: Undefined constant "comma_taxonomy_filter" in /nas/content/live/stagelask/wp-content/themes/Avada-Child-Theme/functions.php:31\nStack trace:\n#0 /nas/content/live/stagelask/wp-settings.php(591): include()\n#1 /nas/content/live/stagelask/wp-config.php(119): require_once('/nas/content/li...')\n#2 /nas/content/live/stagelask/wp-load.php(50): require_once('/nas/content/li...')\n#3 /nas/content/live/stagelask/wp-blog-header.php(13): require_once('/nas/content/li...')\n#4 /nas/content/live/stagelask/index.php(17): require('/nas/content/li...')\n#5 {main}\n thrown in /nas/content/live/stagelask/wp-content/themes/Avada-Child-Theme/functions.php on line 31, referer: https://stagelask.wpengine.com
I first did some research to see if there was a fix for this. Then I tried (unsuccessfully) to define the constant comma_taxonomy_filter.
Any help would be appreciated.
Thanks, Mark
Only need to fix the second parameter of the add_filter()
calls to be strings:
add_filter('get_the_taxonomies', 'comma_taxonomies_filter');
add_filter('get_terms', 'comma_taxonomies_filter');
add_filter('get_the_terms', 'comma_taxonomies_filter');