Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

lacheney on "Comma in foreach output"

$
0
0

Hi,

I'm trying to find posts of a certain type that share taxonomy terms with the current single post being displayed.

Here's my code:

$mentionslist = wp_get_post_terms($post->ID, 'employer-mention', array()); 

if ($mentionslist) {
$mentionsoutput = '';
  foreach($mentionslist as $mention) {
    $mentionsoutput = $mentionsoutput.','.$mention->term_id;
  }
}

echo $mentionsoutput;

The echo of $mentionsoutput returns: ,575,576,1636

What I would like to do is remove the comma which appears right at the beginning so that I can use the variable in a term ID array. Which part of my foreach is wrong?

Thanks,

Lewis


Viewing all articles
Browse latest Browse all 8245

Trending Articles