admin管理员组文章数量:1415635
I have a website that display car/vehicle listings. Each listing displays the PRICE. The price is set as a custom field on a custom post type, that is set to a string data type. The user typically types the price in as like 8,999. I need to echo/output/display the data with the comma removed, like this: 8999
Currently I display the data like this:
<?php echo get_post_meta($post->ID, "_price", true); ?>
How can I use str_replace to output this data without the comma? Or is there a simpler, better way? Any suggestions would be appreciated.
I have a website that display car/vehicle listings. Each listing displays the PRICE. The price is set as a custom field on a custom post type, that is set to a string data type. The user typically types the price in as like 8,999. I need to echo/output/display the data with the comma removed, like this: 8999
Currently I display the data like this:
<?php echo get_post_meta($post->ID, "_price", true); ?>
How can I use str_replace to output this data without the comma? Or is there a simpler, better way? Any suggestions would be appreciated.
Share Improve this question asked Aug 15, 2019 at 0:35 PrestonPreston 114 bronze badges 2 |1 Answer
Reset to default 0Literally just figured this out on my own by reviewing str_replace documentation again.
<?php
$price_meta = get_post_meta($post->ID, "_price", true);
$price_meta_stripped = str_replace(',', '', $price_meta);
echo $price_meta_stripped;
?>
本文标签: Custom Meta FieldRemove comma from string with strreplace
版权声明:本文标题:Custom Meta Field - Remove comma from string with str_replace 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745240391a2649293.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$price = get_post_meta( $post->ID, '_price', true ); echo str_replace( ',', '', $price );
would do it. – Sally CJ Commented Aug 15, 2019 at 5:29