Hey, here is a link:
https://pasteboard.co/zj9tvefusVun.png
The issue:
We have minimum/maximum players numbers (two separate acf fields). Unfortunately, some games can have a minimum of 2 players and maximum of 2 players at the same time, which is problematic. We want to change it, so that we extract those values and create an array within a separate acf field.
For example:
If we have minimum players:2 and maximum 4, we would generate an array of 2,3,4 for that game.
Now, we want to use that array to display as a checkbox within Filter Everything. So the Player range would be an array of all available games, most likely 1,2,3,4,5,6, and based on that users can choose the desired amount of players.
Until this stage all is good, the issue is when selecting that certain checkbox, it then doesn’t display any results.
Hope you can either help solve this issue, or propose some other solution on how to achieve the same thing.
Here is the code we are using to generate the arrays:
function generate_player_range($post_id) {
// Avoid running on ACF field save (to prevent infinite loops)
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
// Get the minimum and maximum player values (corrected field names)
$min_players = get_field('minimum_players', $post_id);
$max_players = get_field('maximum_players', $post_id);
// Check if both values are set and valid
if ($min_players && $max_players && is_numeric($min_players) && is_numeric($max_players)) {
// Create an array of player numbers between min and max (inclusive)
$player_range = range($min_players, $max_players);
// Save the array as a comma-separated string (not as an array)
update_field('player_range_array', implode(',', $player_range), $post_id);
}
}
add_action('acf/save_post', 'generate_player_range', 20); // Run after saving the post
Thanks a lot
-
This reply was modified 1 week ago by juvee.