Saltar navegación

[Resuelto] Formula

This support ticket is created hace 4 años, 7 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Este tema contiene 17 respuestas, tiene 2 mensajes.

Última actualización por marcelB-4 hace 4 años, 7 meses.

Asistido por: Minesh.

Autor
Mensajes
#1637651

I try in English:
I have two entry fields:
Number of games
Number of goals

I would like to calculate the percentage value automatically.
Can that be done in a view?
100 / number of goals * number of games

how do I have to include this in the view?

#1638287

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You need to add the custom shortcode to perform such a calculation.

Toolset offers the place namely "Custom Code" where you can add the custom code:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

For example - please try to add the following code to functions.php file or "Custom Code" section:

function func_calculate_percentage( $atts ) {
 
// Attributes
$atts = shortcode_atts(
array(
'post_id' => ''),$atts);
 
$num_of_games = get_post_meta( $atts['post_id'], 'wpcf-number-of-games', true);
$num_of_goals = get_post_meta( $atts['post_id'], 'wpcf-number-of-goals', true);
$formula = (100 / ($num_of_games *  $num_of_goals ));
return  $formula ;
 
}
add_shortcode( 'display_per', 'func_calculate_percentage' );

Where:
- Please feel free to adjust your field slug and formula as per your requrirement.

And within your view - you can call the above shortcocde as:

[display_per post_id='[wpv-post-id]']

More info;
- https://toolset.com/documentation/adding-custom-code/how-to-create-a-custom-shortcode/

#1638295

I did, unfortunately does not work 🙁

#1638301

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Can you please share the problem URL where you added your view as well as access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.

#1638323

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

With the following page: enlace oculto

I can see you added two different views. Can you please tell me where exactly I need to place the shortcocde I shared or can you place the shortcode at your desired place?

[display_per post_id='[wpv-post-id]']

The issue was the code snippet you added was not active because please make sure you need to add your custom code to every snippet after the following line:

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

So, the code looks now:

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

function func_calculate_percentage( $atts ) {
  
// Attributes
$atts = shortcode_atts(
array(
'post_id' => ''),$atts);
  
$num_of_games = get_post_meta( $atts['post_id'], 'wpcf-total-spiele-national-league', true);
$num_of_goals = get_post_meta( $atts['post_id'], 'wpcf-total-tore-national-league', true);
$formula = (100 / ($total-spiele-national-league *  $total-tore-national-league ));
return  $formula ;
  
}
add_shortcode( 'display_per', 'func_calculate_percentage' );

I've done this for your snippet "spieletoreprozent", you should add all custom code to your every snippet after the above line.

Can you please try to add the shortcode to your desired place [display_per post_id='[wpv-post-id]'] and it should work.

#1638333

enlace oculto

Total Goals / Games tab
But still not shown.
Another problem is that men are on the left and women on the right

#1638337

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Can you please share the link where you added the shortcode? [display_per post_id='[wpv-post-id]']

#1638339
test.png

enlace oculto

#1638341

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

You are not getting me. I mean where in the backend (admin) side you added the shortcode? [display_per post_id='[wpv-post-id]']

To which view? Can you please share direct link of that view?

#1638351

enlace oculto

#1638355

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

It seems there is confusion what you want and what I shared.

So, I shared the solution that will generate the percentage for each post based on the formula you shared.
==> (100 / number of goals * number of games)

Do you want to calculate the percentage based on the all posts values?
If yes: for which view? as I can see you are using multiple views on your page. Please share the view link for which you want to calculate the percentage based on your all posts.

If the above information is not correct, please explain what values I should count on to calculate the average.

#1638357

That is the problem when I write in English.
So:
this view:
enlace oculto
shows number of games
this view:
enlace oculto
shows number of goals
The goal is to calculate how many goals per game.

The result comes in the layout:
enlace oculto

in the 3rd tab

#1638369

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I am not sure why I do not able to delete the things on your layout. Can you please remove the tab4 and tab5 from your layout?

In addition to that if you confirm that this is your formula: 100 / (number of goals * number of games)
- Is your formula is correct? as to get the number of goals per game you need to divide ( number of goals / nuber of games)

#1638435

Of course you are right
Number of goals / number of games

Tabs is deleted

#1638443

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I adjusted the snipped code as per Number of goals / number of games.
=> enlace oculto

I've created the following view;
=> enlace oculto

and added the above view to the tab 4 on the following page. Please check the tab 4:
=> enlace oculto