I'm trying to display custom fields on my post like this:
<ul>
<li><?php the_field('name_of_placement'); ?></li>
<?php
$terms = get_the_terms( get_the_ID(), 'country' );
$names = array();
foreach ( $terms as $term ) {
$names[] = $term->name;
}
echo '<li>' . implode( ', ', $names ) . '<li>';
?>
<?php
$terms = get_the_terms( get_the_ID(), 'timeframe' );
$names = array();
foreach ( $terms as $term ) {
$names[] = $term->name;
}
echo '<li>' . implode( ', ', $names ) . '<li>';
?>
<li><?php the_terms( get_the_ID(), 'types_of_healthcare_placement' ); ?></li>
</ul>
The problem is like this form creates an extra blank <li>
item after each field.
/
How can i fix it?
I'm trying to display custom fields on my post like this:
<ul>
<li><?php the_field('name_of_placement'); ?></li>
<?php
$terms = get_the_terms( get_the_ID(), 'country' );
$names = array();
foreach ( $terms as $term ) {
$names[] = $term->name;
}
echo '<li>' . implode( ', ', $names ) . '<li>';
?>
<?php
$terms = get_the_terms( get_the_ID(), 'timeframe' );
$names = array();
foreach ( $terms as $term ) {
$names[] = $term->name;
}
echo '<li>' . implode( ', ', $names ) . '<li>';
?>
<li><?php the_terms( get_the_ID(), 'types_of_healthcare_placement' ); ?></li>
</ul>
The problem is like this form creates an extra blank <li>
item after each field.
http://electives-abroad/custom-field-test/
How can i fix it?
Share Improve this question edited Apr 29, 2019 at 13:08 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Apr 29, 2019 at 12:33 Draws Ren GundamDraws Ren Gundam 251 gold badge2 silver badges6 bronze badges 01 Answer
Reset to default 1The code seems to be good to me, may be try to correct this line :
echo '<li>' . implode( ', ', $names ) . '<li>';
To :
echo '<li>' . implode( ', ', $names ) . '</li>';
You forget to close the li tag.
Same thing here :
echo '<li>' . implode( ', ', $names ) . '</li>';