I'm using the following code on my WordPress install:
function add_glossary_links($content) {
global $wpdb, $wordlist;
if ( !$wordlist && !$wordlist = get_option('wordlist') ) {
mysql_query('SET SESSION group_concat_max_len = 100000');
$wordlist = $wpdb->get_var('SELECT GROUP_CONCAT(DISTINCT post_title SEPARATOR "|") AS list FROM '.$wpdb->posts.' WHERE post_status="publish" AND post_type="glossary" AND post_parent>0');
add_option('wordlist', $wordlist);
}
$wordlist = str_replace(array(" ", "'", "."), array("\s", "\'", "\."), $wordlist);
echo $wordlist;
$content = preg_replace_callback(
'/\b('.$wordlist.')\b/i',
create_function(
'$matches',
'return "<a href=\"/glossary/" . strtolower(substr($matches[0],0,1) . "/" . $matches[0]) . "/\">" . $matches[0] . "</a>";'
),
$content
);
return preg_replace('/(<[^<]+)<a\s.*?>(.*?)<\/a>/si','$1$2', $content);
}
add_filter( 'the_content', 'add_glossary_links' );
The idea is that I get a list of words from my database; if they exist I replace them with links to the appropriate glossary term.
$wordlist is echoing out as this: http://pastebin.com/6XnWBJwM
The error that I'm receiving is this:
Warning: preg_replace_callback(): Unknown modifier 'c' in /my.website/wp-content/themes/mytheme/functions.php on line 384
Line 384 is the last line of this segment:
$content = preg_replace_callback(
'/\b('.$wordlist.')\b/i',
create_function(
'$matches',
'return "<a href=\"/glossary/" . strtolower(substr($matches[0],0,1) . "/" . $matches[0]) . "/\">" . $matches[0] . "</a>";'
),
$content
);
I presume there's a problem with the formatting of the regexp and the way the wordlist is displaying but I can't for the life of me fathom it.
Thanks in advance,