Home › Forums › Add-ons › Flexible Content Field › Flexible Content to Releationship to Flexible Content
Hi!
Im sitting and developing a site where I use the Flexible Content and in one of my “layouts” i use Relationship to a post type called “widget”.
In this widget I use Flexible Content again and when I’m trying to get a field from this Flexible Content it’s dead end.
I have tried to query the post type “widget” directly and output the data from Flexible Content and that’s fine. But when I’m having the Flexible Content releationship to pick up the data from this post type’s Flexible Content it’s not working like I want it too.
This is my code so far:
<?php if( have_rows('modules') ): ?>
<?php while ( have_rows('modules') ) : the_row(); ?>
<?php if( get_row_layout() == 'content' ): ?>
<?php $widgets = get_sub_field('widgets'); if($widgets && !get_sub_field('full_width')): ?>
<?php foreach( $widgets as $post): ?>
<?php setup_postdata($post); ?>
<?php if( have_rows('widgets') ): ?>
<?php while ( have_rows('widgets') ) : the_row(); ?>
<!-- I can get it to output here, but not further... -->
<?php if( get_row_layout() == 'test' ): ?>
<!-- Here it SHOULD output something, but it doesn't. Why? -->
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
What happens if you add the post ID to the inner flexible field?
<?php if( have_rows('widgets', $post->ID) ): ?>
<?php while ( have_rows('widgets', $post->ID) )
Hi!
I didn’t have to try that way now because I solved the problem by looking through my code once again and I found the damn problem…
When I check for a relationship I used this code:
<?php $widgets = get_sub_field('widgets'); if($widgets && !get_sub_field('full_width')): ?>
<?php foreach( $widgets as $post): ?>
<?php setup_postdata($post); ?>
And when I then checked for the Flexible Content inside this “widget” I used this code:
<?php if( have_rows('widgets') ): ?>
<?php while ( have_rows('widgets') ) : the_row(); ?>
This obviously didn’t work so I figured out that maybe the name of my flexible content “widgets” was conflicting with the relationship get_sub_field(‘widgets’). So I changed name on my Flexible Content field to “widgets_flexible” and it worked…
Thanks anyway!
Ah I see! Glad it worked out then! 🙂
Please feel free to post any other issues with ACF you have in the future.
Have a nice weekend.
You must be logged in to reply to this topic.
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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.