Support

Account

Home Forums General Issues Dynamic Options Values

Helping

Dynamic Options Values

  • I apologize in advance if this is a simple answer, I don’t have a lot of experience with PHP and I haven’t been successful searching the documentation or internet for a solution.

    I’m having some trouble figuring out how to display content from an options page. I have an options page called Exercises with multiple repeaters based on the different muscle groups. Inside those repeaters, is a Title field, 2 image fields and an Embed field.

    Now everything with the options page is working fine, my issue is coming from another field group that is dynamically populating the exercises from the options page into a select field. This page is set up to allow the user to select the different exercise options for daily training, so for example on Monday if they wanted this day to be a Biceps exercise, they’d select Biceps and then choose from the select field which Biceps exercises to include for this workout. It’s able to list the exercises and you can choose one, but I have no idea how I can go about retrieving the rest of the fields from the options page based on the users choice.

    I created a new field on the options page that would create an auto-generated value, I was thinking this may help to link the users selection to the rest of the data.

    EXAMPLE:
    field name: bicep_id
    values: bicep_key_0, bicep_key_1 and so on…

    I altered my dynamic select choice to return the bicep_id as the value, see below.

    function acf_load_select_biceps_field_choices( $field ) {
        
        // reset choices
        $field['select_biceps'] = array();
    
        // if has rows
        if( have_rows('biceps', 'option') ) {
            
            // while has rows
            while( have_rows('biceps', 'option') ) {
                
                // instantiate row
                the_row();
                
                
                // vars
                $title = get_sub_field('title');
    	    $value = (int)get_sub_field('bicep_id');
    
                
                // append to choices
                $field['choices'][ $value ] =  $title ;
                
            }
            
        }
    
        // return the field
        return $field;
        
    }
    add_filter('acf/load_field/name=select_biceps', 'acf_load_select_biceps_field_choices');

    And I have written an if statement to determine if the two fields have the same value, but I’m still stuck on what to do next. I included the names of the sub_fields from the options page with the if statement for reference.

    I feel like I’m running into a brick wall, so any help or advice is greatly appreciated.
    Thanks!

    
    // Dynamic Select Field Value
    $bicep_list = get_sub_field('select_biceps');
    
    // Exercise Options Page
    $biceps = get_sub_field('biceps','options');
    $bicep_id = $biceps['bicep_id'];
    $bicep_title = $biceps['title'];
    $bicep_image1 = $biceps['starting_point_image'];
    $bicep_image2 = $biceps['finishing_point_image'];
    $bicep_video = $biceps['video_url'];
    	
    if($bicep_id == $bicep_list) {
    	if( have_rows('biceps') ): while ( have_rows('biceps') ) : the_row();
        echo '<a href="#" class="bg-exercise">';
    		echo '<span class="text-uppercase font-17 color-white">';
    		echo get_sub_field('select_biceps');
    		echo '</span><br>';
    		echo '<span class="font-button-reps font-15">';
    		echo get_sub_field('sets');
    		echo ' SETS | ';
    		echo get_sub_field('reps');
    		echo ' REPS</span><br>';
    		echo get_sub_field('starting_point_image, options');
    		echo '</a>';
    	endwhile; endif;
      } else {
        echo 'Variables are not equal';
      }
  • Can anyone help me please?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.