Accueil › Toolset Professional Support › [Fermé] Math operators
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | 9:00 – 18:00 | - |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
Marqué : Types plugin
This topic contains 10 réponses, has 2 voix.
Last updated by Waqas Il y a 8 années et 7 mois.
Assisted by: Waqas.
hello,
I would make a math operation:
I have 10 predictions (odds)
odds = [types field="cote"][/types]
I would like the average odds ??
Is this possible with types and views ?
Shortcode creation with function ? or another ?
Thanks
Yes you can create a custom short code for this. Please look at https://toolset.com/forums/topic/calculate-average-from-custom-field/#post-185057 for a solution.
Please consider following code, and add this to your theme's functions.php file:
function my_average_func() { $slug = "wpcf-cote"; global $wpdb; $res = $wpdb->get_var( "SELECT AVG(meta_value) FROM $wpdb->postmeta WHERE meta_key = '$slug' AND meta_value !=''" ); return $res; } add_shortcode( 'my_average', 'my_average_func' );
And use the new short code as below:
[my_average]
This will return average of all values found for 'wpcf-cote' field.
hello,
Thanks for this answer.
I did that.
but I can not seem to get the average ratings for user or for views.
Thanks.
Can you please share the code for your View? That how you are using this short code.
hello,
<table width="100%" cellspacing="0" cellpadding="0"> <thead><tr id="presentation"> <th class="sports">[wpv-heading name="types-field-sports"]Sports[/wpv-heading]</th> <th class="pays">[wpv-heading name="types-field-pays"]Pays[/wpv-heading]</th> <th>Compétitions</th> <th>[wpv-heading name="types-field-date-du-match"]Date du match[/wpv-heading]</th> <th>Match</th> <th>[wpv-heading name="types-field-pari"]Pari[/wpv-heading]</th> <th>[wpv-heading name="types-field-cote"]Cote[/wpv-heading]</th> <th>[wpv-heading name="types-field-bookmaker"]Bookmaker[/wpv-heading]</th> <th>[wpv-heading name="types-field-indice-confiance"]Fiabilité[/wpv-heading]</th> <th>[wpv-heading name="types-field-analyse"]Plus d'infos[/wpv-heading]</th> <th>[wpv-heading name="author-avatar"]Tipster[/wpv-heading]</th> <th>Partager</th> </tr></thead> <tbody> <wpv-loop> <tr class="[wpv-post-class]"> <td class="sports"><div class="[types field="sports"][/types]"><a href="pronostics/[types field="sports"][/types]">[types field="sports"][/types]</a></div></td> <td class="pays"><div class="[types field="pays"][/types]">[types field="pays"][/types]</div></td> <td>[types field="competitions-football"][/types] [types field="competitions-rugby"][/types] [types field="tournois-homme"][/types] [types field="tournois-femme"][/types] [types field="competitions-basket"][/types] [types field="competitions-handball"][/types] [types field="competitions-volley"][/types] [types field="competitions-hockey"][/types] [types field="competitions-footus"][/types]</td> <td class="datematch"><a href="[wpv-post-url]">[types field="date-du-match" style="text" format="d/m/Y à G:i"][/types]</a></td> <td class="equipe"><a href="[wpv-post-url]">[types field="equipe-domicile-ligue1"][/types] [wpv-if f1="wpcf-equipe-exterieur-ligue1" evaluate="$f1 != ''"]- [types field="equipe-exterieur-ligue1"][/types][/wpv-if] [types field="equipe-domicile-ligue2"][/types] [wpv-if f1="wpcf-equipe-exterieur-ligue2" evaluate="$f1 != ''"]- [types field="equipe-exterieur-ligue2"][/types][/wpv-if] [types field="equipe-domicile-bundesliga"][/types] [wpv-if f1="wpcf-equipe-exterieur-bundesliga" evaluate="$f1 != ''"]- [types field="equipe-exterieur-bundesliga"][/types][/wpv-if] [types field="equipe-domicile-liga"][/types] [wpv-if f1="wpcf-equipe-exterieur-liga" evaluate="$f1 != ''"]- [types field="equipe-exterieur-liga"][/types][/wpv-if] [types field="equipe-domicile-premier-league"][/types] [wpv-if f1="wpcf-equipe-exterieur-premier-league" evaluate="$f1 != ''"]- [types field="equipe-exterieur-premier-league"][/types][/wpv-if] [types field="equipe-domicile-seriea"][/types] [wpv-if f1="wpcf-equipe-exterieur-seriea" evaluate="$f1 != ''"]- [types field="equipe-exterieur-seriea"][/types][/wpv-if][types field="equipe-domicile-top14"][/types] [wpv-if f1="wpcf-equipe-exterieur-top14" evaluate="$f1 != ''"]- [types field="equipe-exterieur-top14"][/types][/wpv-if] [types field="equipe-domicile-aviva-premiership"][/types] [wpv-if f1="wpcf-equipe-exterieur-aviva-premiership" evaluate="$f1 != ''"]- [types field="equipe-exterieur-aviva-premiership"][/types][/wpv-if] [types field="tennis-joueur1-homme"][/types] [wpv-if f1="wpcf-tennis-joueur2-homme" evaluate="$f1 != ''"]- [types field="tennis-joueur2-homme"][/types][/wpv-if] [types field="tennis-joueur1-femme"][/types] [wpv-if f1="wpcf-tennis-joueur2-femme" evaluate="$f1 != ''"]- [types field="tennis-joueur2-femme"][/types][/wpv-if] [types field="equipe-domicile-nba"][/types] [wpv-if f1="wpcf-equipe-exterieur-nba" evaluate="$f1 != ''"]- [types field="equipe-exterieur-nba"][/types][/wpv-if] [types field="equipe-domicile-proa"][/types] [wpv-if f1="wpcf-equipe-exterieur-proa" evaluate="$f1 != ''"]- [types field="equipe-exterieur-proa"][/types][/wpv-if] [types field="equipe-domicile-prob"][/types] [wpv-if f1="wpcf-equipe-exterieur-prob" evaluate="$f1 != ''"]- [types field="equipe-exterieur-prob"][/types][/wpv-if] [types field="equipe-domicile-d1"][/types] [wpv-if f1="wpcf-equipe-exterieur-d1" evaluate="$f1 != ''"]- [types field="equipe-exterieur-d1"][/types][/wpv-if] [types field="equipe-domicile-liguea"][/types] [wpv-if f1="wpcf-equipe-exterieur-liguea" evaluate="$f1 != ''"]- [types field="equipe-exterieur-liguea"][/types][/wpv-if] [types field="equipe-domicile-nhl"][/types] [wpv-if f1="wpcf-equipe-exterieur-nhl" evaluate="$f1 != ''"]- [types field="equipe-exterieur-nhl"][/types][/wpv-if] [types field="equipe-domicile-ligue-magnus"][/types] [wpv-if f1="wpcf-equipe-exterieur-ligue-magnus" evaluate="$f1 != ''"]- [types field="equipe-exterieur-ligue-magnus"][/types][/wpv-if] [types field="equipe-domicile-nfl"][/types] [wpv-if f1="wpcf-equipe-exterieur-nfl" evaluate="$f1 != ''"]- [types field="equipe-exterieur-nfl"][/types][/wpv-if] </a></td> <td class="pari">[toolset_access role="Guest" operator="allow"] <a href="<em><u>hidden link</u></em>" class="register screen-reader-shortcut">Inscrivez <br/>vous</a> [/toolset_access][toolset_access role="Administrator,Subscriber" operator="allow"][types field="pari"][/types][/toolset_access]</td> <td class="cote">[types field="cote"][/types]</td> <td class="bookmaker"><div class="[types field="bookmaker"][/types]"><span> [wpv-if f1="wpcf-bookmaker" evaluate="$f1 = 'betclic'"]<a href="<em><u>hidden link</u></em> " target="_blank"><img src="<em><u>hidden link</u></em>"/></a>[/wpv-if] [wpv-if f2="wpcf-bookmaker" evaluate="$f2 = 'bwin'"] <a href="<em><u>hidden link</u></em> " target="_blank"><img src="<em><u>hidden link</u></em>"/></a>[/wpv-if] [wpv-if f3="wpcf-bookmaker" evaluate="$f3 = 'francepari'"]<a href="<em><u>hidden link</u></em>" target="_blank"><img src="<em><u>hidden link</u></em>"/></a>[/wpv-if] [wpv-if f4="wpcf-bookmaker" evaluate="$f4 = 'joaonline'"]<a href="<em><u>hidden link</u></em>" target="_blank"><img src="<em><u>hidden link</u></em>"/></a>[/wpv-if] [wpv-if f5="wpcf-bookmaker" evaluate="$f5 = 'netbet'"]<img src="<em><u>hidden link</u></em>"/>[/wpv-if] [wpv-if f6="wpcf-bookmaker" evaluate="$f6 = 'parionsweb'"]<a href="<em><u>hidden link</u></em>" target="_blank"><img src="<em><u>hidden link</u></em>"/></a>[/wpv-if] [wpv-if f7="wpcf-bookmaker" evaluate="$f7 = 'pmu'"]<img src="<em><u>hidden link</u></em>"/>[/wpv-if] [wpv-if f8="wpcf-bookmaker" evaluate="$f8 = 'unibet'"]<a href="<em><u>hidden link</u></em>" target="_blank"><img src="<em><u>hidden link</u></em>"/></a>[/wpv-if] [wpv-if f9="wpcf-bookmaker" evaluate="$f9 = 'winamax'"]<img src="<em><u>hidden link</u></em>"/>[/wpv-if] [wpv-if f10="wpcf-bookmaker" evaluate="$f10 = 'bookmakers_com'"]<img src="<em><u>hidden link</u></em>"/>[/wpv-if] </span></div> <td><div class="[types field="indice-confiance"][/types]"><span>[types field="indice-confiance" format="FIELD_NAME: FIELD_VALUE"]</span></div></td> <td class="analyse"><a href="[wpv-post-url]"><span class="infos">+</span> Infos</a> </td> <td class="tipster"><a href="[wpv-url]">[wpv-gravatar]</a> </td> <td class="partage"><div class="facebook">[social4i size="small" align="" type="s4_fbshare"]</div><div class="twitter">[social4i size="small" align="" type="s4_twitter"]</div></td> </tr> </wpv-loop> </tbody> </table>
And function.php :
function prefix_show_only_page_author( $query_args ) { global $bp; global $WP_Views; $view_id = $WP_Views->get_current_view(); if($view_id == 565){ $types = (array) $query_args['post_type']; if ( in_array( 'pronostic', $types ) ) { $query_args['author'] = empty( $bp->displayed_user->id) ? -1 : $bp->displayed_user->id; } } elseif($view_id == 1367){ $types = (array) $query_args['post_type']; if ( in_array( 'pronostic', $types ) ) { $query_args['author'] = empty( $bp->displayed_user->id) ? -1 : $bp->displayed_user->id; } } return $query_args; }
Thanks
I couldn't find the short code (I mentioned in my previous message) in your View's code. I am not sure where do you want to use it. So I am unable to suggest the exact place for this.
However, from screen shot and View's code perspective. If you notice the PHP code of [my_average] short code. It does a query to calculate average on "all" wpcf-cote fields. If you require to limit it for particular set of posts, you need to edit the code accordingly.
Anyhow, can I ask for a temporary access to your site? So I can look for more details.
I have enabled your next reply as private, please input all details in that area. Please mention the links to the pages, views, forms, CPTs and configurations in question.
Please take a backup of your site, before proceeding.
Thank you for providing the details. Please allow me some time to work on this. I will update you as soon as I find a solution.
Thanks !!
I am trying to understand the page at hidden link but I am unable to see any results. So apparently I can not figure out what are the columns, so I can play with values and can help building some results.
However, as far as I understand that your view is based on several parametric attributes, so apparently you need to adjust [my_average] short code to fulfil the query parameters. So you can take appropriate average.
For example, if the listings (assuming a screen shot you sent earlier) are about a particular player. And cote field is all about him, you might want to add the query to [my_average] short code's function. So the results are confined to that particular player.
The short code function I supplied is a generic one, which returns value for "each and every" cote field found in the database (regardless of view's parametric filters).
Looks like you need to customise the short code function.
Le sujet ‘[Fermé] Math operators’ est fermé à de nouvelles réponses.