Support

Account

Home Forums General Issues Getting a field object if it is conditional upon the value of the current field

Solved

Getting a field object if it is conditional upon the value of the current field

  • Is there currently any way to access field objects that are conditionally dependent on the current field object?

    I’m running through the choices of a field object and for each of them I’d like to grab fields that are conditional upon the value of the current field object.

    Thanks in advance! 🙂

    function bmdcf_font_archive_sidebar() { 
        
        // field key works but not slug, don't know why...
        $font_cats_field = get_field_object('field_5e865743f2ea2');
        $font_categories = $font_cats_field['choices'];
        $fonts_archive_url = get_term_link('fonts', 'download_category');
        
        ?>
        
        <h3><?php esc_html_e('Categories', 'text_domain')?></h3>
        
        <ul>
        
        <?php foreach ( $font_categories as $font_category_slug => $font_category_label ) { ?>
           
            <li>
                <a href = "<?php echo $fonts_archive_url . '/?fontcategory=' . $font_category_slug; ?>">
                    <?php echo $font_category_label; ?>
                </a>
                
            <?php 
            // if has a field that is conditional upon the the value of the $font_cats_field, put this here
            // my goal here is to display the choices of subcategories
            ?>
            </li>
    
        <?php } ?>
        
        </ul>
        
    <?php }
  • No, the condition is set on the conditional field not on the field that the condition is dependent on. The field that they are dependent on is not aware of the conditional fields in any way.

    There is a way. You would need to get all of the field objects

    
    $all_objects = get_field_objects();
    

    Then loop over the entire list checking the conditional logic for each field.

  • Thanks so much, I didn’t think of that! I really appreciate it! 🙂

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

The topic ‘Getting a field object if it is conditional upon the value of the current field’ is closed to new replies.