Saturday, 15 March 2014

wordpress - Need help getting a specific key's post meta data, from all posts in a specific post type, into a comma seperated string variable -



wordpress - Need help getting a specific key's post meta data, from all posts in a specific post type, into a comma seperated string variable -

wordpress: ok have post type category called wineries , each winery post there custom field called address in each wineries' address listed. create total page google map of these wineries marked. in order need take of address custom field info every post , set 1 comma separated string variable in order pass google map. have fiddled around while , figured should help. here have came far. able echo of addresses onto page using foreach statement, doesn't me good

$posts = get_posts(array( 'post_type' => 'wineries', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids' ) ); foreach($posts $p){ $ads = get_post_meta($p,"address",true); echo $ads; echo','; }

$str = ''; foreach($posts $p){ $ads = get_post_meta($p,"address",true); if($ads) $str .= $ads.','; } $str = substr($str,0,-1);

pass string,$str google map.

wordpress google-maps metadata

No comments:

Post a Comment