Home Forums General Issues Get sub_field from another layout on same page


Get sub_field from another layout on same page

  • I don’t know if I’m asking this correctly, but here’s what I’d like to do.

    How do I get the value of a sub_field from one layout and use it in another sub_field from a different layout. Both layouts are on the page.

    Specifically, I’d want to get the background color of a div (div_background_color) and use the value, a hex color, to change the text color in another div.

    Does that make sense? Need more info?

  • This is guess, but I think I know what you are looking for.

    <?php $bg_color = get_sub_field('div_background_color'); ?>
    <div style="background-color:<?php echo $bg_color; ?>">
    <!-- content -->

    Further down the page in your other layout you would just need to <?php echo $bg_color; ?> in the bg style declaration.

    Let me know if I am way off base with your request, but I’m hoping I got it right 🙂

  • decay… that worked perfectly. That’s basically what I had been trying but I was missing something, not sure what. Thanks!!!

  • @swolock awesome. Glad I could help 🙂

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

The topic ‘Get sub_field from another layout on same page’ is closed to new replies.