• Resolved juvee

    (@juvee)


    Hey,

    I have a player range in ACF, which is an array [1,2,3,4] which displays as a checkbox. Unfortunately, this makes the filter not show the results (but narrows other filters – which is good). Is there a fix for it so that arrays can be used within the ACF field and displayed as a checkbox and so it shows results correctly?

    • This topic was modified 1 week, 1 day ago by juvee.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support fesupportteam

    (@fesupportteam)

    Hi @juvee

    Thank you for your interest in the Filter Everything plugin.

    Can you please send the link to the screens of the ACF field so we can check it? this is a bit confusing description:

    I have a player range in ACF, which is an array [1,2,3,4] which displays as a checkbox.?

    Best Regards – Victor

    Thread Starter juvee

    (@juvee)

    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.
    Plugin Support fesupportteam

    (@fesupportteam)

    @juvee

    You can create a checkbox custom field with the predefined values like:

    1
    2
    3
    4
    5
    6
    7

    So when you go to your post you choose the needed values, and by this custom field, you can create a filter set.

    Best Regards – Victor

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.