Support

Account

Home Forums Front-end Issues list from post_object field isn't displayed correctly

Solved

list from post_object field isn't displayed correctly

  • Hello,

    I have created a post-object field and would like to output this as an unordered list. The list is also generated. However, there are empty bullets between all entries. How can I prevent this?
    Here is my code:

    <?php $post_objects = get_field( 'field1' ); ?> <?php if ( $post_objects ): ?>
    
        <?php foreach ( $post_objects as $post ): ?> <?php setup_postdata( $post ); ?>
    
        "><?php the_title(); ?>
        <?php endforeach; ?>
    
    <?php wp_reset_postdata(); ?> <?php endif; ?>

    Here you can see the wrong display of the list:
    wrong list items

    Many thanks for your help.
    Michael

  • There is something missing from the code you attempted to include.

  • Sorry, here’s the complete code.:

    
    <?php $post_objects = get_field( 'field1' ); ?>
    	<?php if ( $post_objects ): ?>
    		<ul>
    			<?php foreach ( $post_objects as $post ):  ?>
    			<?php setup_postdata( $post ); ?>
    			<li>
    				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    			<li>
    		<?php endforeach; ?>
    		</ul>
    		<?php wp_reset_postdata(); ?>
    	<?php endif; ?>
    
  • Okay, I found the mistake. It was just a silly missing / in the closing

  • -tag.
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘list from post_object field isn't displayed correctly’ is closed to new replies.