Support » Plugins » Hacks » PHP – Using ProgPress Thermometer with a global custom field value

  • I’m using the ProgPress thermometer plugin for a fundraising site. In my header, I have the following PHP code to include the thermometer on the page:

    if (function_exists('jcp_progpress_generate_meter')){
           echo jcp_progpress_generate_meter("title", 40000, 0, 0, "label");

    In the function, the third value (the ‘0’ after 40000) is defined as $current (the current value). So 40,000 is the objective, 0 is the value raised thus far. All works as it should if I update this value in the php code. But, my client would like to update it themselves in the WP admin area.

    Is there a way to use a global custom field to define this value in a way the client can update themselves? I know this involves some PHP, which unfortunately I don’t know well.

    To see the thermometer style, please see:

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You could try

    Create a custom option called ‘Amount raised so far’ with a slug of ‘raised-so-far’ then replace the 0 in your code with

    get_custom_option ( 'raised-so-far', 0)


    echo jcp_progpress_generate_meter("title", 40000, get_custom_option ( 'raised-so-far', 0), 0, "label");

    the client can then use Admin->Settings->Options to change the value as the money rolls in

    Thank you for your prompt reply, it is working well! I’m using the same value to populate the number above the text “Raised So Far”, directly below the thermometer. It is working well here too, but I’d love to see a comma added. Obviously a comma breaks the thermometer function, so it can’t be added in the option setting itself. Here’s the code I have now:

    if (function_exists('jcp_progpress_generate_meter')){
           echo jcp_progpress_generate_meter("title", 40000, get_custom_option ('raised-so-far', 0), 0, "label");
    <div id="goal"><span class="thermometer_numbers">$40,000</span> <br />
    Campaign Goal</div>
    <div id="raised"><span class="thermometer_numbers">$<?php
    echo get_custom_option ('raised-so-far', 0); ?>

    Two choices,

    Create a new custom option, e.g. ‘display-raised-so-far’ and enter a value of $1,000 then display that, or, format the number,

    $nf = new NumberrFormatter('en-US', NumberFormatter::CURRENCY);
    $nf->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 0);
    echo $nf->format(get_custom_option ('raised-so-far', 0));

    untested, but should print $1,000 for a value of 1000

    I would advise checking for a valid integer when getting and displaying your custom option.


    Thanks again, Ian for taking the time to respond. Much appreciated!

    I’d like to set the value in one place to keep it simple for my client. I tried your code, but was unable to get it going; it seemed to break the code at the number value.

    I tried the number_format option, to output the comma:

    $nf = (get_custom_option ('raised-so-far', 0));
    echo number_format($nf);

    Since I already have the ‘$’ for the currency as part of the HTML. This did work, adding the desired comma. So thank you, seeing your php syntax helped me along, I’m pretty green at this.


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP – Using ProgPress Thermometer with a global custom field value’ is closed to new replies.