Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Marcel,
You mean you want the view to be always sorted based on one of the columns ?
Right now i see that you have it sorted based on the number of Games they played. I'm a little confused.
Is it that you want the user to adjust the sorting on the frontend themselves if they want ?
Please let me know.
Thanks,
Shane
Hi
No, it should be sorted according to the 3rd column (Ø).
Highest value first
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Marcel,
Now I fully understand the issue.
Unfortunately no you won't be able to sort by this vale. The reason is because the value to be sorted is being generated dynamically by your custom shortcode "[display_per post_id='[wpv-post-id]']" .
There isn't a stored value in the database that views can use to sort the information. You can sort your view by the other columns but not by this one.
Thanks,
Shane
that is not good at all. So this column doesn't make sense 🙁
What options do I have?
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Marcel,
Right now the options are actually limited because unless the value is on the post itself then it cannot be sorted.
So you can only sort by the Name, Games and Goals.
Thanks,
Shane
Can you have the calculated value entered into a field (automatically) so that I can sort it? Or would I have to do it all manually
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Marcel,
This would require some modification to your custom code to allow for it to hook into your post to update a custom field that would hold these values.
If we modified the code then you will need to go through each of your post and update your posts so that the value gets applied to the custom field.
As long as its a custom field that is stored on the post itself we can have it sorted.
Please let me know if this is ok.
Thanks,
Shane
That would be great. Is that always automatically entered?
That would be nice
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Marcel,
It will be automatically entered but given that your posts are already created you will need to go through each post and click the update button so the code can automatically update the field itself.
What I want you to do is to go into Types and create a custom field that can hold this value.
Once you have done this please let me know and we can continue from there.
Thanks,
Shane
I created:
Percent / Games / Goals
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Marcel,
I'm not sure which field this is that was created in Types. Here is a screenshot
Can you confirm that this is the field that the value is to be stored in ?
Thanks,
Shane
Hi
Yes, that's the right field
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Marcel,
Add the following to the custom code section on your site.
function update_games_total_field($post_id) {
if(get_post_type($post_id) == 'player'){
$num_of_games = get_post_meta( $post_id, 'wpcf-total-spiele-national-league', true);
$num_of_goals = get_post_meta( $post_id, 'wpcf-total-tore-national-league', true);
$formula = (($num_of_goals / $num_of_games ));
update_post_meta($post_id,'wpcf-prozent_games-goals',number_format($formula,2));
}
}
add_action( 'save_post', 'update_games_total_field', 9999, 1 );
This custom code section is found in Toolset -> Settings -> Custom Code. Add it and enable it.
Once you've done this you will then need to go through all your posts and hit the update post button one by one. Finally just set your view to be sorted by the "prozent_games-goals" field and it should order it correctly.
Please let me know if this helps.
Thanks,
Shane
Everything done that way. However, it doesn't work
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Marcel,
This should now be working, the problem was that you didnt enable to code to run on the backend. See Screenshot
I've enabled it so that the code now runs on the Admin section of the site.
Please let me know if this helps.
Thanks,
Shane