Hi, Luo. good day.
I m trying to create an independent custom field based on a calculation.
There is no custom calculation field at the moment, so i am not sure how to achieve this.
I understand the direct shortcode method BUT that's just for simple display value.
what I need it a custom field that can be used to
1. filter accending/descending
2. use AT custom search
3. display its value .
Pls, advise how to achieve this. Much appreciated. My login valid the same for you to test.
Pls note there are existing code snippets at
lien caché
Sorry, i miss this critical details to give you. :
the custom field name to be created is " Price Per Square Feet "
The calculation/formula is field - property price/field property size. thank you.
Dear C6410,
Thanks for the details, there is a misunderstand, the shortcode [wpv-calculate] can only display the calculated result, but the result does not existed in database, it can not be used for:
1. filter accending/descending
2. use AT custom search
If you need to filter by(order by) the calculated result, you will need to save it into database as a custom field, so I suggest you try like this:
1) When user create/edit a post, use action hook save_post to trigger an PHP function
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
2) in the PHP function, do these:
a) calculate result
b) save it into database as a custom field
https://codex.wordpress.org/Function_Reference/update_post_meta
For those posts have already existed in your website, you will need to update them one by one.
For your reference.
Thanks for the detail explanations.
on the concern of the database resources i think best for now is just to perform manual calculations ?
Could you describe more details for the question:
for now is just to perform manual calculations ?
I just tested the custom shortcode [wpv-calculate] in your website:
lien caché
[wpv-calculate] 1+1+1 [/wpv-calculate]
It does out 3 in front-end, it works fine.
HI Luo.
yes the custom field is working fine to display the calculations, BUT i need to use these values for
1. sorting/filter
2 custom search min.max search.
for this to happen i think all the calculated values need to be stored at the db ?
pls let me know if you need more info. thanks
As I mentioned above, there isn't such a built-in feature within Toolset plugin,
the custom shortcode [wpv-calculate] can not be used for:
1. filter accending/descending
2. use AT custom search
If you insist on above features, please check my answer:
https://toolset.com/forums/topic/an-independent-custom-field-based-on-a-simple-calculations/#post-572375
Please let me know if you need other assistance. thanks