Support

Account

Home Forums Front-end Issues Count what select field options was chosen Reply To: Count what select field options was chosen

  • In your query you must include the quotes

    
    'value' => '"'.$dev_id.'"', // matches exactly "123", not just 123. This prevents a match for "1234"
    

    In your loop you actually need to count the totals for each selection, I’m not 100% certain this will do what you want.

    
    $counts = array();
    if ($doctors) {
      foreach ($doctors as $doctor) {
        $value = get_field('bedrooms', $doctor-ID);
        echo $value;
        if (!isset($counts[$value])) {
          $counts[$value] = 0;
        }
        $counts[$value]++;
      } // end foreach
    } // end if
    echo array_search(min($counts), $counts); // min
    echo array_search(max($counts), $counts); // max