php - Get value separated by comma WordPress -
how value separated comma. used explode
it. i've tried.
$get_item_desc = get_post_meta ($post->id, 'item_description', true); $arr = explode(",", $get_item_desc); $item_string = ''; foreach($arr $val){ echo $get_items = $item_string.trim($val).' '; }
sample input:
item 1, item 2, item 3
sample output:
desc-1: item 1 desc-2: item 2 desc-3: item 3
based on sample input/output, can use:
$get_item_desc = get_post_meta($post->id, 'item_description', true); $arr = explode(',', $get_item_desc); $i = 1; foreach($arr $val){ echo 'desc-' . $i . ': ' . trim($val) . ' '; $i++; }
Comments
Post a Comment