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 (http://codex.wordpress.org/Class_Reference/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;
endforeach;
endif;
return $field;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.