Skip Navigation

[Resuelto] An independent Custom field based on a simple calculations.

This support ticket is created hace 7 años, 2 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Autor
Mensajes
#572363

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
enlace oculto

#572364

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.

#572375

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.

#572391

Thanks for the detail explanations.
on the concern of the database resources i think best for now is just to perform manual calculations ?

#572437

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:
enlace oculto
[wpv-calculate] 1+1+1 [/wpv-calculate]
It does out 3 in front-end, it works fine.

#572438

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

#572447

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