Home › Forums › Backend Issues (wp-admin) › Dynamically Load Select Choices with Functions › Reply To: Dynamically Load Select Choices with Functions
Sorry about that – I believe we have the correct use of the variable now, but it doesn’t seem to be working correctly. Here’s everything I know:
'name' => 'select_waiting_list',
with 'choices' => array(),
in functions.php.function get_waiting_lists( $field ) {
$field['choices'] = array();
// Query Waiting Lists Products
$args = array(
'post_type' => 'memberpressproduct',
'orderby' => 'name',
'order' => 'ASC',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'topics',
'field' => 'id',
'terms' => '22',
'operator' => 'IN'
),
)
);
$lists_array = get_posts( $args );
foreach ( $lists_array as $list ) {
$choices[$list->ID] = $list->post_title;
}
$field['choices'] = $choices;
wp_reset_postdata();
return $field;
}
add_filter('acf/load_field/name=select_waiting_list', 'get_waiting_lists');
array(1) { ["choices"]=> array(2) { [449]=> string(26) "Waiting List - Millionaire" [623]=> string(29) "Waiting List - Small Business" } }
<select id="acf-field-connect_waiting_list" class="select" name="fields[field_5272b350a4105]"><option value="null">- Select -</option><option value="choices"></option></select>
Thank you again, so much, for your help sorting this out. You guys have such great support.
– Ross
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.