Title: Numeric Calculation
Last modified: February 3, 2022

---

# Numeric Calculation

 *  [in-business](https://wordpress.org/support/users/in-business/)
 * (@in-business)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/numeric-calculation-2/)
 * Hello again,
 * Sorry to keep asking lots of questions, but once I have the main setup done, 
   I will be good to go…so thank you for your patience.
 * Is there a way with the current version, or possibly with your upgraded version
   to count entries in a “Multiselect Checkbox” – so for example, if the multiselect
   was as follows:
 * Car Design:
 *  – Leather seats: Checked
    – Alloy wheels: Checked – Metallic paint: Unchecked–
   Satnav: Unchecked – Diesel: Checked
 * So in this case all the “Checked” items would equate to 1 and all the “Unchecked”
   items would equate to 0, which means the total would equal 3 in the above example.
 * Thank you

Viewing 15 replies - 16 through 30 (of 94 total)

[←](https://wordpress.org/support/topic/numeric-calculation-2/?output_format=md)
[1](https://wordpress.org/support/topic/numeric-calculation-2/?output_format=md)
2 [3](https://wordpress.org/support/topic/numeric-calculation-2/page/3/?output_format=md)…
[5](https://wordpress.org/support/topic/numeric-calculation-2/page/5/?output_format=md)
[6](https://wordpress.org/support/topic/numeric-calculation-2/page/6/?output_format=md)
[7](https://wordpress.org/support/topic/numeric-calculation-2/page/7/?output_format=md)
[→](https://wordpress.org/support/topic/numeric-calculation-2/page/3/?output_format=md)

 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15334898)
 * No, you have to construct your calculation template without using calculated 
   fields in the template.
 *  [crowwoods1](https://wordpress.org/support/users/crowwoods1/)
 * (@crowwoods1)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15334902)
 * You mean I can construct a calculation template in the numeric field?
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15334958)
 * You must construct the calculation template in the Numeric Calculation field 
   that does not use other Numeric Calculation fields.
 * Numeric fields are a different thing: they do not have the ability to make calculations,
   they simply store a number. You can use those in the calculation template.
 *  [crowwoods1](https://wordpress.org/support/users/crowwoods1/)
 * (@crowwoods1)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15334986)
 * It sounds like I can’t use the Numeric Calculation field at all because it won’t
   be updated when the participant first updates their records. Only after their
   updates are recorded in the database before the Numeric Calculation field could
   work. That means the first Save is just to record their numeric fields, and the
   2nd Save is to do the Numeric Calculation fields.
 * My question is: can I write custom html in the attributes area of a numeric field
   to add up the points instead?
 *  [crowwoods1](https://wordpress.org/support/users/crowwoods1/)
 * (@crowwoods1)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15334991)
 * I mean use JavaScript in the attributes.
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15335039)
 * The Numeric Calculation field can work, because it looks for the current value
   in the Numeric fields, it doesn’t need to wait for the submission.
 * The difference between a Numeric field and A Numeric calculation field is that
   a numeric field is a static value, it doesn’t have to be calculated, so its value
   is available on the first submission.
 * As I’ve said from the beginning, the best way to do this is to write a bit of
   custom php to get the job done. You can put simple javascript in the field attribute
   configuration, but may be difficult to get it to work that way.
 *  [crowwoods1](https://wordpress.org/support/users/crowwoods1/)
 * (@crowwoods1)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15343572)
 * I do this custom coding in pdb-record-custom.php. Right?
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15343788)
 * I don’t recognize the filename, but if that is a plugin, yes, that’s a good place
   to put it. If that is a template, then no, that won’t work.
 * The code should go into a plugin, or you can put it into your [theme functions.php](https://www.wpbeginner.com/glossary/functions-php/)
   file.
 *  [crowwoods1](https://wordpress.org/support/users/crowwoods1/)
 * (@crowwoods1)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15343926)
 * That was pdb-records-default.php in the plugins/participant database/template
   folder, copied over to the participant database template folder and renamed. 
   That was the wrong file?!
 * What is the name of the plugin you’re talking about? And where is it?
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15344075)
 * That is correct for a template file, but you can’t put the filter code in there.
   Try adding it to your functions.php file, I provided a link to help you do that.
 *  [crowwoods1](https://wordpress.org/support/users/crowwoods1/)
 * (@crowwoods1)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15348959)
 * Roland,
 * I want to see if I can do my Plan B, which is to pass the participant data to
   a 3-party form that can do the point calculations. I’ve already set everything
   up in that form to gather the actions, do the calculations, and post it back 
   to the database. But seeing how it can’t tell who’s logged-in in pdb, I don’t
   know if there’s a way to pass the id from one to the other, when they’re connected
   by a link.
 * Thanks, Ivy!
 *  [crowwoods1](https://wordpress.org/support/users/crowwoods1/)
 * (@crowwoods1)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15352875)
 * Roland,
 * ok, I’m back to doing the calculations in a php file. I am putting it in a Code
   Snippets file. Can you tell me what the hook name should be for doing the calculations
   in the Participant Record? I assume my custom code comes in when the user press
   Save.
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15353706)
 * The filter to use is [pdb-calculated_field_calc_value](https://xnau.com/work/wordpress-plugins/participants-database/participants-database-documentation/participants-database-api/#pdb-calculated-field-calc-value).
 * I put together a simple plugin that provides an example of its use:
 * [https://gist.github.com/xnau/9bc6bfa1046e0f2927d25a10ce185ed6](https://gist.github.com/xnau/9bc6bfa1046e0f2927d25a10ce185ed6)
 *  [crowwoods1](https://wordpress.org/support/users/crowwoods1/)
 * (@crowwoods1)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15356985)
 * Thank you so much, Roland!
 * I modified it for my purpose, but nothing gets written to the database.
 * It almost sounds like the return would do it. I have 4 calculated fields to write
   back to the database, so I put this at the end of the program.
 *  $result = array($role_points, $one_time_points, $regular_points, $total_points);
   
   return $result; }
 * What do I need to write back to the database?
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/2/#post-15357494)
 * It will write to the database normally, you don’t need to do anything because
   the calculation is performed when the record is updated.
 * If you look at the plugin debugging log (with debugging enabled) you’ll see the
   write.

Viewing 15 replies - 16 through 30 (of 94 total)

[←](https://wordpress.org/support/topic/numeric-calculation-2/?output_format=md)
[1](https://wordpress.org/support/topic/numeric-calculation-2/?output_format=md)
2 [3](https://wordpress.org/support/topic/numeric-calculation-2/page/3/?output_format=md)…
[5](https://wordpress.org/support/topic/numeric-calculation-2/page/5/?output_format=md)
[6](https://wordpress.org/support/topic/numeric-calculation-2/page/6/?output_format=md)
[7](https://wordpress.org/support/topic/numeric-calculation-2/page/7/?output_format=md)
[→](https://wordpress.org/support/topic/numeric-calculation-2/page/3/?output_format=md)

The topic ‘Numeric Calculation’ is closed to new replies.

 * ![](https://ps.w.org/participants-database/assets/icon-256x256.jpg?rev=1389807)
 * [Participants Database](https://wordpress.org/plugins/participants-database/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/participants-database/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/participants-database/)
 * [Active Topics](https://wordpress.org/support/plugin/participants-database/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/participants-database/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/participants-database/reviews/)

 * 94 replies
 * 3 participants
 * Last reply from: [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/numeric-calculation-2/page/7/#post-15429988)
 * Status: not resolved