Reputation: 29
I have a function wpb_nos_formules() which makes an show répéteur field . How can fix this function? I don't know where the error is error
function wpb_nos_formules()
{
if( have_rows('formule') ): ?>
<?php while( have_rows('formule') ): the_row();
// vars
$title = get_sub_field("title");
?>
<ul>
<li><?php echo $title; ?></li>
</ul>
<?php if( have_rows('slider') ): ?>
<?php while( have_rows('slider') ): the_row();
// vars
$titlee = get_sub_field("title");
$description = get_sub_field("description");
?>
<ul>
<li><?php echo $titlee; ?></li>
<li><?php echo $description; ?></li>
</ul>
<?php endwhile;
endif; ?>
<?php endwhile; ?>
<?php endif;
}
add_shortcode('latest_nos_formule', 'wpb_nos_formules');
Upvotes: 1
Views: 40
Reputation: 11282
I revised your code. Shortcode function should return. and also do not start <?php
and close ?>
multiple times unless not needed.
function wpb_nos_formules(){
$html = '';
if( have_rows('formule') ) : while( have_rows('formule') ) : the_row();
$title = get_sub_field("title");
$html .='<ul>
<li>'.$title.'</li>
</ul>';
if( have_rows('slider') ) : while( have_rows('slider') ) : the_row();
$titlee = get_sub_field("title");
$description = get_sub_field("description");
$html .='<ul>
<li>'.$titlee.'</li>
<li>'.$description.'</li>
</ul>';
endwhile; endif;
endwhile; endif;
return $html;
}
add_shortcode( 'latest_nos_formule', 'wpb_nos_formules' );
Upvotes: 1