Home › Forums › Add-ons › Repeater Field › Pulling in a repeater field, into a post object repeater field
Hello,
I have an issue that I am trying to solve but have seemed to hit a wall on. Here is the scenario.
I have a repeater field on my home page that is a post object so the user can choose what posts they want to display on the home page. Within the post objects (the posts that I select in my post object repeater field) I have another repeater field that I need to pull in. I grabbed some code in another forum and was trying to make it work.
My home page repeater field is named “featured_solutions’
the repeater field in the post that I am trying to pull in is called ‘product_size’
and that repeater field’s sub field is called ‘pipe_size’
I have others, but if I could come up with a solution for one I can reuse that for the other repeater fields that I have.
Any help wit this would be greatly appreicated!
`<?php
if(have_rows(‘featured_solutions’)){
while (have_rows(‘featured_solutions’)) {
the_row();
$featured_sol = get_sub_field(‘featured_solution’);
if($featured_sol){
$fsolimage = get_field(‘page_thumbnail’, $featured_sol->ID);
$fsollink = get_permalink($featured_sol->ID);
$fsoltitle = get_the_title($featured_sol->ID);
$fsolsummary = get_field(‘application_summary’ , $featured_sol->ID);
//$fsolsizes = get_sub_field(‘pipe_size’ , $featured_sol->ID);
$fsolsizes = get_field(‘product_size’ , $featured_sol->ID);
$pipesize = get_sub_field(‘pipe_size’ , $featured_sol->ID);
$fsolapprovals = get_field(‘product_approval’ , $featured_sol->ID);
$applications = get_the_terms( $featured_sol->ID, ‘taxonomy’ );
if($fsolsizes) {
while (has_sub_field(‘product_size’)) {
echo ‘
‘;
}
}
}
echo ‘<div class=”solutionItem”>
<div class=”siImage” style=”background-image:url(‘ . $fsolimage . ‘);”><h3 class=””>’ . $fsoltitle . ‘</h3></div>
<div class=”siPad”>
<div class=”siCopy”>
<div class=”siTop”>
<span>Applications</span>
‘ . $applications->name . ‘
</div>
<div class=”siLeft”>
<span>Sizes</span>
‘ . $pipesize . ‘
</div>
<div class=”siRight”>
<span>Approvals</span>
‘ . $fsolapprovals . ‘
</div>
<div class=”breakline”></div>
<div class=”siCTA”>
<div class=”ctabutton primary”>learn more</div>
</div>
</div>
</div>
</div> ‘ ;
}
}
?>
This seems to work, might be a bit bloated for now, but it is working properly
<?php
if(have_rows('featured_solutions')){
while (have_rows('featured_solutions')) {
the_row();
$featured_sol = get_sub_field('featured_solution');
if($featured_sol){
$fsolimage = get_field('page_thumbnail', $featured_sol->ID);
$fsollink = get_permalink($featured_sol->ID);
$fsoltitle = get_the_title($featured_sol->ID);
//$fsolsizes = get_field('product_size' , $featured_sol->ID);
//$pipesize = get_sub_field('pipe_size' , $featured_sol->ID);
//$fsoapproval = get_sub_field('approval' , $featured_sol->ID);
//$fsolapprovals = get_field('product_approval' , $featured_sol->ID , $fsoapproval[0]);
}
echo '<div class="solutionItem">
<div class="siImage" style="background-image:url(' . $fsolimage . ');"><h3 class="">' . $fsoltitle . '</h3></div>
<div class="siPad">
<div class="siCopy">
<div class="siTop">
<span>Applications</span>
<p>';
$categories = wp_get_post_categories( $featured_sol->ID , array('child_of' => 10 ));
//loop through them
foreach($categories as $c){
$cat = get_category( $c );
//get the name of the category
$cat_id = get_cat_ID( $cat->name );
//make a list item containing a link to the category
$applications = $cat->name;
echo $applications. '<br />';
}
echo '</p>
</div>
<div class="siLeft">
<span>Sizes</span>
<p>';
if(get_field('product_size' , $featured_sol->ID)){
while(has_sub_field('product_size' , $featured_sol->ID)){
echo the_sub_field('pipe_size' , $featured_sol->ID) . '<br />';
}
}
echo '</p>
</div>
<div class="siRight">
<span>Approvals</span>
<p>';
if(get_field('product_approval' , $featured_sol->ID)){
while(has_sub_field('product_approval' , $featured_sol->ID)){
echo the_sub_field('approval' , $featured_sol->ID) . '<br />';
}
}
echo '</p>
</div>
<div class="breakline"></div>
<div class="siCTA">
<div class="ctabutton primary"><a href="' . $fsollink . '">learn more</a></div>
</div>
</div>
</div>
</div> ' ;
}
}
?>
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 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.