Support

Account

Home Forums General Issues Help loop field repeat Reply To: Help loop field repeat

  • Hi Dada

    You probabely kill the query loop by using the setup_postdata(). Try this way (Not functional, just to show you the logical path) :

    $args = array('posts_per_page' => '-1','post_type'	=> 'listas-compras','author' => $user_ID);
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) {
    	while ( $query->have_posts() ) {
    		$query->the_post() ;
    		$listas_id= get_the_ID();
    		$asignar_recetas = get_field('asignar_receta', $listas_id);
    		if ($asignar_recetas) {
    			[...] // Write your html 
    			foreach( $asignar_recetas as $receta) {
    				// each 'receta' is recetas post object
    				$receta_id = $receta->ID;	
    				[...] // Write your html
    				echo '<a href="'.get_permalink($receta).'>">'.get_the_title($receta).'</a>'; // get post data with the post object
    				[...] // Write your html
    				if( have_rows('ingredientes', $receta_id)) { 
    					while ( have_rows('ingredientes', $receta_id)) : the_row(); // get row with the receta_id to avoid mistake
    						[...] // Write your html
    						the_sub_field('cantidad');
    						[...] // Write your html
    						$ingrediente = get_sub_field('ingrediente'); // This is the ingrediente post object
    						[...] // Write your html
    						echo get_the_title($ingrediente);
    						[...] // Write your html
    					endwhile;
    					[...] // Write your html
    				}
    				[...] // Write your html
    			}
    			[...] // Write your html
    		}
    		[...] // Write your html
    	}
    }
    wp_reset_postdata();