• Data returned by GF for multiselect example:
    [“3″,”4″,”5”]

    The exploded array of the above input will return:

    array (size=3)
    0 => string ‘[“3″‘ (length=4)
    1 => string ‘”4″‘ (length=3)
    2 => string ‘”5”]’ (length=4)

    But with if you apply intval to them, it returns

    array (size=3)
    0 => int 0
    1 => int 0
    2 => int 0

    Because of the extra characters (or rather the first character in each array).

    On gfcptaddonbase.php line 487:

    $terms = array_map( ‘intval’, explode( ‘,’, $entry[ $field->id ] ) );

    Don’t know if there’s a good way to convert to int values because brackets. But considering the values area basically in json format, decoding json should work fine.

    $terms = json_decode ($entry[ $field->id ]);

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter ingraye

    (@ingraye)

    Correction to myself, the code should be:
    $terms = array_map( ‘intval’, json_decode($entry[ $field->id ] ));

    To typecast the values into int for hierarchical taxonomies.

    I had this same issue and the correction from @ingraye solved it.

    Using a multiselect field for selecting custom post categories, specifically woocommerce products in my case, was not populating the categories. Editing line 487 as indicated above worked immediately. Hope this gets added to the next update.

    Thanks @ingraye

    @ingraye ‘s solution threw a php warning for us when there was a single term or no term selected, where an array was being expected in the second argument. Solved by replacing line 487 with the following (on v3.1.7 of this plugin) which should allow for some backwards compatibility with multiselect fields from older versions of gravity forms and the above scenario:

    // New versions of GF store multiselect values as a JSON string.
    $values = json_decode($entry[ $field->id ] );
    // Older versions of Gravity Forms store the multiselect values as a comma-delimited list.
    if( ! $values ) {
        $values = explode( ',', $entry[ $field->id ] );
    }
    $terms = array_map( 'intval', $values);
    • This reply was modified 7 years, 2 months ago by discotoast.

    Note: This bug is fixed in v3.1.8.
    – Cam

    I ran into this issue a few months ago, and the fix above worked at the time. But it seems with the latest version of Gravity Forms, the multi select category field is no longer saving values. Single category or multiple.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Bug in multiselect fields -> taxonomy’ is closed to new replies.