Home › Forums › General Issues › repeater query for specific posts
I’m making a plugin that will display my custom field type and it’s associated custom fields, but can’t figure out how to show my custom fields. I’ve repeated 3 e
This is my relative code section:
// kids
$kids = get_field ('children', $post->ID);
if( $kids ) {
$pdf->Ln(10);
$pdf->Write(12, 'we have kids1'); //shows
foreach( $kids as $kid ) {
$pdf->Ln(10); //does NOT SHOW
$pdf ->Write (12, 'a kid'); //does NOT SHOW
$pdf->WriteHTML( $kid['name'] ); //does NOT SHOW
}
}
if( have_rows('children', $post->ID) ):
$pdf->Ln(10);
$pdf->Write(12, 'we have kids2'); //does NOT SHOW
while ( have_rows('children', $post->ID) ) : the_row();
$pdf->Ln(10); //does NOT SHOW
$pdf->Write(12, 'a kid'); //does NOT SHOW
endwhile;
endif;
}
}
This is what is being displayed:
we have kids1
I would expect that I would see
we have kids1
a kid joe
a kid bo
a kid duke
we have kids2
a kid
a kid
a kid
how do I display the child subfield (name)?
Where are you getting the sub field values?
I see nothing in your code to actually get a value from a sub field.
if the field ‘children’ is a repeater then this $kids = get_field ('children', $post->ID);
returns an array in the format
$kid = array(
{$row_index} => array(
'sub_field_name' => 'sub_field_value'
)
)
when using a ‘have_rows()’ loop then you need to use get_sub_field() to get the values for the row.
In the first section of code I was using $pdf->WriteHTML( $kid['name'] ); //does NOT SHOW
to pull the array.
The section section instead of pulling code I was just testing to see if it would output anything. So the “if” statement would return the string “a kid” for each subfield with content. (it’s not returning actual content).
From the code given I see no reason why either of the loops should not work other than ('children', $post->ID)
not having any rows.
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.