I found a work around in the meantime which is to have a plugin that reads add_filter(‘the_content’,’convertqName’) and then to remove_filter it and add_filter(‘the_excerpt’,’convertqName’) in the specific categories page. That seems to work (I presume that the plugin is called every time a new page is loaded so removing the filter only applies on that page).
Why I can’t have a plugin that reads:
add_filter('the_content','convertqName');
add_filter('the_excerpt','convertqName');
remains a mystery to me though.
The function called by the plugin is below.
BTW: the $filterContext variable was the only way I could find to pass a parameter to the function – another cludge and advice on that would be nice too… ??
HB
function convertqName($beginString) {
//return $beginString;
global $wpdb;
global $filterContext;
$endString = $beginString;
// search for qNames by matching {, some characters excluding }, }
$howMany = preg_match_all("|\{([^\}]+)\}|", $beginString, $matches, PREG_PATTERN_ORDER);
for ($i = 0; $i < $howMany; $i++) {
//matches[0][*] contains entire match, matches[1][*] contains match of ([^\}]+)
//i.e. this strips of the {}
//$query = "SELECT resto_name, resto_link, resto_address FROM restaurants WHERE resto_qName = {$matches[1][$i]}";
$query = "SELECT * FROM restaurants WHERE resto_qName = '{$matches[1][$i]}'";
$resto = $wpdb->get_results($query);
//echo($query . " result: " . $resto[0]->resto_link . "<br />");
switch ($filterContext) {
case "posts": //single
$newString = "Restaurant: <b>" . $resto[0]->resto_name . "</b> (" . $resto[0]->resto_cuisine . ") <img src='" . get_bloginfo('url') . "/af/map/" . $resto[0]->resto_rating . "stars.png'> <img src=" . get_bloginfo('home') . "/af/map/" . $resto[0]->resto_price . "euro.png><br /><a href='" . get_bloginfo('home') . "/map/#" . $resto[0]->resto_qName . "'>" . $resto[0]->resto_address . "</a>, " . $resto[0]->resto_tel;
if ($resto[0]->resto_area != "") {$newString .= " (" . $resto[0]->resto_area . ")<br />";}
break;
case "page": //recommendations
$newString = "<b>" . $resto[0]->resto_name . "</b> (" . $resto[0]->resto_cuisine . ") <img src='" . get_bloginfo('home') . "/af/map/" . $resto[0]->resto_rating . "stars.png'> <img src=" . get_bloginfo('home') . "/af/map/" . $resto[0]->resto_price . "euro.png><br />" . $resto[0]->resto_comment;
if ($resto[0]->resto_link != "none") {$newString .= " <a href='" . $resto[0]->resto_link . "'>Review</a>";}
$newString .= "<br /><a href='" . get_bloginfo('home') . "/map/#" . $resto[0]->resto_qName . "'>" . $resto[0]->resto_address . "</a>, " . $resto[0]->resto_tel;
if ($resto[0]->resto_area != "") {$newString .= " (" . $resto[0]->resto_area . ")";}
break;
case "iphone":
$newString = "<div class='cell'><h3>" . $resto[0]->resto_name . "</h3><span>" . $resto[0]->resto_comment . "</span><a href='https://maps.google.com/maps?f=q&hl=en&geocode=&q=" . $resto[0]->resto_name . "@" . $resto[0]->resto_lat . "," . $resto[0]->resto_lng . "&ie=UTF8&t=m&z=17&iwloc=addr'><div class='link'></div></a></div>";
break;
case "rotm":
$newString = "<a href='" . $resto[0]->resto_link . "'>" . $resto[0]->resto_name . "</a>";
break;
case "search":
$newString = "Restaurant: <b>" . $resto[0]->resto_name . "</b> <img src='" . get_bloginfo('url') . "/af/map/" . $resto[0]->resto_rating . "stars.png'> <img src=" . get_bloginfo('home') . "/af/map/" . $resto[0]->resto_price . "euro.png>";
break;
}
$endString = str_replace( $matches[0][$i], $newString, $endString);
}
return $endString;
}