• Resolved Etienne

    (@epipo)


    Hi,

    I wanted to add a select input with custom options to my form but I haven’t found any filter to change the field type and options of a custom field. Could you help?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author roundupwp

    (@roundupwp)

    Hey again E.Pipo,

    Sorry for the delayed response here! The free version doesn’t officially support select fields as of right now. It will likely do so in the future. In the meantime it might be possible with a PHP snippet. I will get back to you by the end of the week with an example.

    – Craig

    Thread Starter Etienne

    (@epipo)

    Hi Craig,

    No worries, thanks for your help! Awesome, I’ll wait for your snippet then, thanks a lot.

    Etienne

    Plugin Author roundupwp

    (@roundupwp)

    Hey Etienne,

    Here are the steps:

    1) Create a custom field (“Custom 2” in this example)
    2) Add this PHP to your functions.php for your theme:

    function ru_custom_select( $field_attributes ) {
    
    	if ( isset( $field_attributes['custom2'] ) ) {
    		$field_attributes['custom2']['type'] = 'select';
    		$field_attributes['custom2']['meta'] = array( 'options' => array() );
    		
    		// array ( LABEL, VALUE, IS PRESELECTED )
    		$field_attributes['custom2']['meta']['options'][] = array( 'First Option', 'First Option Value' , false );
    		$field_attributes['custom2']['meta']['options'][] = array( 'Second Option', 'Second Option Value' , false );
    		$field_attributes['custom2']['meta']['options'][] = array( 'Third Option', 'Third Option Value' , false );
    	}
    
    	return $field_attributes;
    }
    add_filter( 'rtec_fields_attributes', 'ru_custom_select', 10, 1 );

    You can copy and paste the examples ($field_attributes[‘custom2’][‘meta’][‘options’][] = array( ‘First Option’, ‘First Option Value’ , false );) to create more options to select from as needed. If you are using a field other than “Custom 2” change “custom2” parts to match.

    Let me know if you have more questions!

    – Craig

    Thread Starter Etienne

    (@epipo)

    Hi Craig,

    Thanks a lot, it works great! I didn’t see the rtec_fields_attributes filter at the beginning. Extending this question, what about adding:

    – A textarea?
    – A hidden field?

    Thanks again for your help!

    • This reply was modified 5 years, 8 months ago by Etienne.
    Plugin Author roundupwp

    (@roundupwp)

    No problem!

    No other field types are supported even with this filter at the moment. Possibly in the future though!

    We are always trying to balance our Pro vs Free options (the Pro version offers these). I do think it makes sense to include all standard field types (radio, select, checkbox, textarea, number) in the future.

    – Craig

    Thread Starter Etienne

    (@epipo)

    Ok, thanks for your answer. For sure this could make sense to include standard field types but I do understand the business logic behind it. I’ll have a look at the Pro version then.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add field type’ is closed to new replies.