So i have a SQL call that grabs a set of tags and seperates them by commas with implode and explode but for the link area I would like to use the slug i saved in the db instead of the direct value.
$cg;
$tag=$mysqli->query("SELECT * FROM wp_pod_tbl_tags");
while($tags = $tag->fetch_object()){
$ct = explode(",", $categories);
foreach($ct as $c) {
if($tags->id == $c) {
$cg[] = $tags->name;
}
}
}
$arrs = implode(", ", $cg);
$arr = explode(",", $arrs);
$links = array();.0
foreach ($arr as $value) {
$links[] = "<a href='#". trim($value) ."'>". trim($value) ."</a>";
}
$links_str = implode(",", $links);
?>
<span><?=$links_str?></span>
Currently it comes out with <a href=#beer garden>Beer Garden</a> but in my db i have a slug that is beer-garden. So I would like it to be <a href="#beer-garden">Beer Garden</a>. But can’t figure out how to add it. To call it would be $tags->slug.
To get from this
beer-gardento thisBeer Gardenyou need to manipulate the string in two ways:You will have to adapt it to your situation, on the surface, there may be cases where this doesn’t work. Especially when the name is suppose to have a dash.