Adding optgroup dynamically server-side

Home Forums Quform WordPress Adding optgroup dynamically server-side

This topic is: not resolved
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #24330
    Hiyou
    Participant

    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.

    #24386
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy