Home Forums Backend Issues (wp-admin) Fill field with remote data? Reply To: Fill field with remote data?

  • @sporklab for a quick and dirty solution to this, I use jQuery and the acf field ID. Here’s an example below where a metabox is added to a certain post type, and when the user enters an ID in a field and fetches data from a remote API, it fills out some ACF fields:

    function my_metabox_render() { ?>
      <p>Enter the ID:</p>
      <input type="text" id="the_id_for_remote_api" />
      <button id="my_import_button" class="button button-primary button-large">Import</button>  
        jQuery("#my_import_button").on("click", function(e) {
          var theID = jQuery("#the_id_for_remote_api").val();
          var apiEndpoint  = "" + theID + ".json?api_key=some_nifty_key";
          jQuery.get(apiEndpoint, function(data) {
    <?php }
    function register_my_metabox() {
            'Example Metabox Title',
    add_action( 'add_meta_boxes', 'register_my_metabox' );

    Like I said, this is just the rough outline. But it works pretty well for the use case you described. Note that I tend to keep the “remote” field separate from ACF, siloed in the metabox, it just simplifies things.