Home Forums General Issues Dynamic Select from other plugin table? Reply To: Dynamic Select from other plugin table?

  • Nailed it. Thanks.

    A mixture of WordPress Class $wpdb ( and your functions.

    Saved me (for the moment) from having to write a Save to Database function using WordPress. Also means I can keep my Custom Admin Fields all together in ACF, a bit neater that way.

    RoyalSlider places its data in a table called wp_new_royalsliders (obviously table prefix will be custom to each developers WordPress tables).

    add_filter('acf/load_field/name=media_gallery_slider', 'my_acf_royalslider_choices'); 
    function my_acf_royalslider_choices($field){
      $field['choices'] = array();
      // Required to make use of the wpdb Class
      global $wpdb;
      // Query the database
      $query = $wpdb->prepare('SELECT * FROM %1$s ORDER BY ID ASC', 'wp_new_royalsliders');
      $results = $wpdb->get_results($query);
      // Check for $results
      if(!empty($results)) :
      foreach($results as $result) :
          $value = $result->id;
          $label = $result->name;
          $field['choices'][ $value ] = $label; 
      return $field;