'Auto' player lists dont show all players
I have a player list for a season and a team. The players are currently set as 'Auto'. There should be 20 players but it only shows 5-
This appears to be because of the following query:
FROM wp_posts
LEFT JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_postmeta
ON ( wp_posts.ID = wp_postmeta.post_id )
LEFT JOIN wp_postmeta AS mt1
ON ( wp_posts.ID = mt1.post_id )
LEFT JOIN wp_postmeta AS mt2
ON ( wp_posts.ID = mt2.post_id
AND mt2.meta_key = 'sp_assignments' )
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (295) )
AND ( wp_postmeta.meta_key = 'sp_number'
AND ( ( ( mt1.meta_key = 'sp_team'
AND mt1.meta_value = '74' ) )
AND mt2.post_id IS NULL
) )
AND wp_posts.post_type = 'sp_player'
AND ((wp_posts.post_status = 'publish'))
GROUP BY ...
ORDER BY wp_postmeta.meta_value
Any player which has any entries in the 'sp_assignment' meta key are being dropped due to the AND mt2.post_id IS NULL clause. Removing this returns all the players as expected.
Is this a bug or am I misunderstanding the feature?
Hi @tomforster ,
sp_assignments is the solution we implemented to be able to "bind" a player to a specific Team, for a specific Season for a specific League. It saves an info to the player in the following format "league_id-season_id-team_id". As you can see from the code here https://github.com/ThemeBoy/SportsPress/blob/master/modules/sportspress-player-assignments.php , if a player has already defined "assignments" then the system will use them to include him/her to the list. If not, then it will check against League, Season and Team assignments, which may return false positives. It is a "drawback" of how WordPress handles multiple taxonomy relations to posts.
By using a 3nd party plugin like https://wordpress.org/plugins/jsm-show-post-meta/ you can check what data are stored to each of your players and see if the correct sp_assignment was set or not.
Thanks, Savvas
Hi Savvas,
Thank you for the swift reply. That makes a lot of sense. I've just done a player import and it looks like most of my players didnt get the 'meta_value' for the current season added upon import. Is there a way to cause this data to be regenerated?
Additionally, resaving the player appears to have wiped that metadata.