Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a field on the admin side where a user enters a number for a price. If a user enters 1000000 I'd like to be able to display on the front-end $1,000,000.

Any ideas on how to accomplish this?

Edit More details, the post is a custom post type 'property'.

To add the meta fields on the back-end I'm using Meta Box Script, http://www.deluxeblogtips.com/2011/03/meta-box-script-update-v30.html

The code to display the numbers on the front-end I use

$meta = get_post_meta(get_the_ID(), 'rw_propPrice', true); echo $meta;
share|improve this question

2 Answers 2

up vote 3 down vote accepted

To format number, you can use the function number_format_i18n (it's not documented now, but you can see its source here). Its work is format the number based on the language. You might want to look at number_format (PHP built_in function, and is used by number_format_i18n) to have more control to decimal point and thousand separator.

In your case, this code will help you:

$meta = get_post_meta(get_the_ID(), 'rw_propPrice', true);
echo '$' . number_format($meta, 0, '.', ',');
share|improve this answer
    
thanks, for the answer, for your blog, the Meta Box Script... everything, it's been a huge help with my first wordpress project –  Chuck Jun 17 '11 at 1:43
    
You're welcome :) –  Rilwis Jun 17 '11 at 3:15

Just a guess (you really need to be more specific in your Q - what screen, how did you add it, metabox/settings section/bla???)...

$foo = get_option( 'your_option_name' ); 
echo '$'.$foo['bar']; // where bar is the searched value in the options array
share|improve this answer
    
I have added more details, I figure I can add the dollar sign in between echo and $meta; but still not sure how to add comma's. Thanks. –  Chuck Jun 17 '11 at 1:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.