I would like help to calculate search input field with custom fields in posts. The result should appear in the view loop.
I have the code for calculating two custom fields and it works fine calculating the values of the posts in the view loop:
// Calculate shortcode
add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts) {
return wpv_condition($atts);
}
Using this shortcode to calculate the fields in view loop:
[wpv-calculate evaluate=" [types field='bredde' format='FIELD_VALUE'][/types] + [types field='pris' format='FIELD_VALUE'] [/types] "]
In the view search there is a field to enter height. When the user enters any height, it should take this value and calculate with the custom fields and the result should then appear for every post in the view loop.
Note that the posts have the height as a number custom field in the field group for the post type, which is why it is provided in the view search. But the posts doesn't have the height values entered, as the user needs to type this in the view search first, making it able to calculate with the other custom fields. Those other custom fields already have a defined value.
But when testing it gives the error: "Error while parsing the evaluate expression".
And it seems like it still search the custom field "folieprint-hojde" and "folieprint-bredde" even though there are no values in these fields for the posts.
So, if your requirement is that the calculation should work only when both search params are available then you should uses the following conditional statement. It will check that if both params are available then it will run the shortcode [wpv-calculate].
[wpv-conditional if="( '[wpv-search-term param='wpv-wpcf-folieprint-hojde']' ne '' ) AND ( '[wpv-search-term param='wpv-wpcf-folieprint-bredde']' ne '' )"]
[wpv-calculate evaluate=" [wpv-search-term param='wpv-wpcf-folieprint-hojde'] * [wpv-search-term param='wpv-wpcf-folieprint-bredde'] * [types field='pris-folieprint' format='FIELD_VALUE'] [/types] "]
[/wpv-conditional]
I've just tested again. But the problem is now, that it doesn't produce any results, unless the posts have values in these fields; 'wpv-wpcf-folieprint-hojde' and 'wpv-wpcf-folieprint-hojde'.
These fields shouldn't have any value in the post, because the customer needs to enter values in view search for these fields manually for the calculation. In field settings, i've tried setting Type of control to "Using manually entered values" but with no luck.
Can you please share problem URL where you added your view and admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Last thing, how can i make it possible to use comma instead of dot, when typing a value with decimals?
For example the height will be entered as 2 * 3,2 (with comma instead of dot)
New threads created by Minesh and linked to this one are listed below:
Glad to know that solution I shared help you to resolve your original issue reported with this ticket..
As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery for the original issue reported.