I'v been looking at several tutorials and stackoverflow answers, but I can't get this to work for me. Basically, I want tp echo the number of instances a certain string is mentioned through all posts.
Here's what I've cobbled together so far using answers I've read. I'm putting this inside a loop for a page template:
$count = 0;
$sql = mysql_query("SELECT LENGTH(post_content) - LENGTH(REPLACE(post_content,'string I want to count','')) AS 'occurs' FROM wp_db WHERE post_content LIKE '%string I want to count%'");
while ($data = mysql_fetch_assoc($sql)) {
$count += $data['occurs'];
}
echo $count;
This seems to break my template though and nothing gets echoed.
Hoping someone can help me recognize what I'm doing wrong here. Any help is, as always, greatly appreciated!