Title: <abbr title="Not Safe For Work / Mature content">[NSFW]</abbr> Comparing two fields (if not empty)
Last modified: January 20, 2024

---

# [NSFW] Comparing two fields (if not empty)

 *  Resolved [rotertal](https://wordpress.org/support/users/rotertal/)
 * (@rotertal)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/comparing-two-fields-if-not-empty/)
 * Hi CodePeople!
 * I have two currency fields (fieldname1 and fieldname2) and a calculated field(
   fieldname3). I want to compare the entries of the currency fields (only if these
   are filled):
   fieldname3 => IF(fieldname1|r === fieldname2|r),1,0)This works nice,
   however, when I want to put it into the following function, empty currency fields
   are treated as “0” and therefore result in 1:
 * (function() {
   if (fieldname1 !== “” && fieldname2 !== “” && fieldname1 === fieldname2){
   return 1;} else {return 0;}})();
 * What can I do?
 * Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/comparing-two-fields-if-not-empty/#post-17359088)
 * Hello [@rotertal](https://wordpress.org/support/users/rotertal/)
 * The plugin preprocesses the fields’ values to use them in mathematical operations.
   If you want to access the field’s raw value, use it with the |r modifier.
 * Please edit the code as follows:
 *     ```wp-block-code
       (function() {
           if (fieldname1|r !== "" && fieldname2|r !== "" && fieldname1 === fieldname2) {
               return 1;
           } else {
               return 0;
           }
       })();
       ```
   
 * Best regards.
 *  Thread Starter [rotertal](https://wordpress.org/support/users/rotertal/)
 * (@rotertal)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/comparing-two-fields-if-not-empty/#post-17359462)
 * Thank you, now it works!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘[NSFW] Comparing two fields (if not empty)’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [rotertal](https://wordpress.org/support/users/rotertal/)
 * Last activity: [2 years, 4 months ago](https://wordpress.org/support/topic/comparing-two-fields-if-not-empty/#post-17359462)
 * Status: resolved