WordPress.org

Ready to get started?Download WordPress

Forums

Taxonomy Picker
Default "selected" value is not set for multiple values (3 posts)

  1. rooby
    Member
    Posted 1 year ago #

    When you have a multiple value select field and select more than one value and then submit, when the form reloads the selected options are lost.

    This does not happen if you only select one value.

    The reason is that this plugin modfies multiple values that are posted and makes them a comma delimited string. This string is then checked to see if it matches an option to apply the "selected" attribute.

    Multiple comma delimited values will not match a single value.

    To fix it I change taxonomy-picker-library.php at line 335:

    $selected = '';
    				if( empty($tpicker_inputs) ):
    					$selected = ($data_item['value'] == ($taxonomy_name . '=' . $term->slug) ) ? 'on' : '';
    				else:
    					$input_value = $tpicker_inputs[$taxonomy_name];
    					$selected = ( $input_value == $term->slug) ? 'on' : '';
    				endif;

    To be this:

    if( empty($tpicker_inputs) ):
    					$selected = ($data_item['value'] == ($taxonomy_name . '=' . $term->slug) ) ? 'on' : '';
    				else:
    					$input_value = $tpicker_inputs[$taxonomy_name];
    					// Multiple values are comma delimited.
    					$input_value = explode(',', $input_value);
    					if (in_array($term->slug, $input_value)) {
    						$selected = 'on';
    					}
    				endif;

    http://wordpress.org/extend/plugins/taxonomy-picker/

  2. rooby
    Member
    Posted 1 year ago #

    The first code sample in the above wasn't meant to include the first line
    $Selected = '';

    But seeing as I can't edit my post and there is no preview button there is little I can do about fixing it.

  3. Modyssee
    Member
    Posted 1 year ago #

    It doesn't works, it create multiple errors (and my code is not on line 335 but on line 667)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.