Pulling out only the unique tags from all records

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 5, 2017   (RSS)

By Dave - July 5, 2017

Hi Hiroko, 

Try this: 

<?php
  // get sorted unique tag list
  $tagList = [];
  foreach ($newsRecords as $record) {
    $recordTags = explode(',', $record['tags']);
    foreach ($recordTags as $tag) { $tagList[] = $tag; }
  }
  $tagList = array_unique($tagList);
  natcasesort($tagList);
?>

<?php foreach ($tagList as $tagLink): ?>
  <a href="<?php echo PREFIX_URL ?>/search-result.php?q=<?php echo urlencode($tagLink) ?>&input=Search"><?php echo htmlencode($tagLink) ?></a>
<?php endforeach ?>

Let me know if that works for you!

Dave Edis - Senior Developer
interactivetools.com

By hiroko - July 5, 2017

Hello Dave,

It worked out great. Thank you so much!

Hiroko