Support

Account

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