Navigation überspringen

[Gelöst] view sort

This support ticket is created vor 4 Jahren, 7 Monaten. 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Dieses Thema enthält 33 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von marcelB-4 vor 4 Jahren, 7 Monaten.

Assistiert von: Shane.

Author
Artikel
#1646995

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

#1647253

Hi
No, it should be sorted according to the 3rd column (Ø).
Highest value first

#1647731

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

#1647749

that is not good at all. So this column doesn't make sense 🙁
What options do I have?

#1647787

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

#1647975

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

#1648013

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

#1648019

That would be great. Is that always automatically entered?
That would be nice

#1648061

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

#1648063

I created:
Percent / Games / Goals

#1648095

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Screenshot 2020-06-02 at 3.25.44 PM.png

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

#1648645

Hi
Yes, that's the right field

#1649491

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

#1649911

Everything done that way. However, it doesn't work

#1650547

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Screenshot 2020-06-04 at 8.57.23 AM.png

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