Home Forums General Issues repeater query for specific posts


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->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->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

    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.

  • Thanks for looking. I appreciate it. MERRY CHRISTMAS TOO!

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

You must be logged in to reply to this topic.