Home Forums Backend Issues (wp-admin) Append dynamic choices to specific field(radio buttons)


Append dynamic choices to specific field(radio buttons)

  • Hi.
    – WordPress Ver. 5.4.1
    – ACF Ver. 5.8.11
    – Post editor: Gutenberg

    I created a field group which contains following fields.

    – Text field [text]
    – Button field [custom field]
    – Radio button field [radio] : This field has just one choice by default. Later append choices via AJAX.

    When I click the button, get a data from the text field and pass it to my custom JS to get JSON data from a remote server. So far I successfully get JSON data and display it in my browser console.

    What I want to do next is to use this JSON data to add radio button choices in same block, but there seems to be no filters return HTML suitable for the radio button field.

    I looked through core functions and found the file includes/fields/class-acf-field-radio.php which has member function render_field but no hooks.

    I think this is used for HTML output.
    line 135:

    $e .= '<li><label' . $class . '><input ' . acf_esc_attr( $atts ) . '/>' . $label . '</label></li>';

    Is there any way to pass my JSON data to this function and get HTML?

    I could manually make HTML and insert it by JS but there is no ID or class to target.

    Radio buttons output is like following:

    <ul class="acf-radio-list acf-hl" id="NEED-SOME-UNIQUE-ID-HERE!">
          <input type="radio" id="acf-block_XXXXX-field_YYYYY" name="acf-block_XXXX[field_YYYY]" value="">LABEL

    Any help will be appreciated.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.