Support

Account

Home Forums General Issues Number field that can be unlimited

Solved

Number field that can be unlimited

  • Just discovered ACF. It’s incredible! Thanks to the team 🙂

    My project is to list cellular phone plans in table and list, accordingly to some caracteristics.

    For some caracteristics, I would like to be able to use fields that could be multiple numbers from 1 to xxxx, but that could also be ‘unlimited’. As a example, to show data limit of the plans (in GB), which could be unlimited with some plans.

    I will later use the content from this field to filter/sort the plans in a table, from 0 to unlimited (and the opposite).

    What kind of field should I use?

  • A number field.

    Assuming that you have a range of 1 to 9999 before unlimited and you want unlimited to be sorted as highest then you would represent unlimited with 10000.

    At least that’s the way I’d do it.

    Or if I was going to make it easy for the client I would have a radio field to select “unlimited” or “set limit” and then a number field to allow setting the limit with a max value. This number field would be conditional based on the radio field. Then I would create an acf/save_post action that would set this number field to 10000 if the radio field was set to unlimited making unseen by the user.

  • Great answer! Thanks 👍

    May I ask what you would do about the frontend, to show unlimited instead of 10000 in WPDatables?

  • 
    $value = get_field('field_name');
    if ($value == 10000) {
      $value = 'Unlimited';
    }
    echo $value;
    

    or use https://www.advancedcustomfields.com/resources/acf-format_value/

  • Thanks again!!

    If I choose option to make the number field conditional based on the radio field, and I choose defaut value of 10 000, will that specific value be saved in database if unlimited is choosen (and number field hidden)?

  • No, fields that are hidden by conditional logic are not saved. This is why you need the filter if you choose to go that route.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.