-1

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.org/custom-field-test/

How can i fix it?

1

The 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>';
  • Now it looks ok, instead of having a closing </li>, every sentence had another opening <li> Why does the 'types_of_healthcare_placement' taxonomy appear blank? it should be the same as the other two. – Draws Ren Gundam Apr 29 '19 at 12:52
  • +1. And @DrawsRenGundam, are you sure the taxonomy slug (types_of_healthcare_placement) is correct? And that there are actually terms in that taxonomy which are assigned to the post? – Sally CJ Apr 29 '19 at 13:25
  • My bad, it was just "healthcare". Now it appears correctly: electives-abroad.org/custom-field-test Problem solved. – Draws Ren Gundam Apr 29 '19 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.