Home › Forums › Backend Issues (wp-admin) › Dynamically populate a select field’s choices from the options page EXTENDED › Reply To: Dynamically populate a select field’s choices from the options page EXTENDED
Hey Elliot, thanks for this push. Since I am using a checkbox which will pass an array instead of a single value, i used this:
// vars
$includedCrossSells = get_field('ssm_cross_sells_list', $id);
$crossSellTitle = get_sub_field('ssm_cross_sell_title', 'option');
// find matching row
if ( have_rows('ssm_cross_sells', 'option') ) {
while ( have_rows('ssm_cross_sells', 'option' ) ) {
the_row();
if ( in_array( (get_sub_field('ssm_cross_sell_title', 'option')), $includedCrossSells ) ) {
echo '<a href="' . get_sub_field('ssm_cross_sell_link', 'option') . '"><img src="' . get_sub_field('ssm_cross_sell_image', 'option') . '"</></a>';
echo '<p><a href="' . get_sub_field('ssm_cross_sell_link', 'option') . '">' . get_sub_field('ssm_cross_sell_title', 'option') . '</a></p>';
}
}
}
This works, but what is interesting is that when i pass $crossSellTitle
as a variable which takes get_sub_field('ssm_cross_sell_title', 'option');
as a value, instead of using the full get_sub_field('ssm_cross_sell_title', 'option');
it doesn’t work. Can you spot why that is?
Thank you so much
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.