Home › Forums › Quform WordPress › Adding optgroup dynamically server-side
Hi, I understand we can add optgroup with Quform. With the following dynamic population of data
add_action('quform_pre_display_1', function (Quform_Form $form) { $select = $form->getElement('quform_1_3');
if ($select) { $options = array(); $posts = get_posts(array('numberposts' => -1, 'post_type' => 'travel'));
foreach ($posts as $post) { $options[] = array('label' => $post->post_title, 'value' => $post->post_title, 'id' => $post->ID); }
$select->setOptions($options); } });
How do I add optgroup dynamically as well? E.g. if I want to group id 1-100 in one group, and 101-200 in another group. Thank you.
You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.