Support

Account

Home Forums Front-end Issues get_the_title($post->ID) only shows outside my loop

Solved

get_the_title($post->ID) only shows outside my loop

  • I am trying to show a table based on ACF fields
    http://pnw.focusww.com/roster/

    I can show my title field outside the <tr> block but it does not show up inside the block. (it is currently visible above the table)

    Can anyone give me a hint as to what I’m missing???

    my loop code is:

    if( $posts ):
        foreach( $posts as $post ):
    	$fww_title = get_the_title( $post->ID );
    	$echo $fww_title;?>
    	   <tr>
    		<td><a href="<?php $fww_permalink; ?>"><?php $fww_title; ?></a></td>
    		<td>test</td>
    		<td><?php the_field('player_gender', $post->ID); ?></td>
    		<td><?php the_field('player_level', $post->ID);  ?></td>
    		<td><?php echo the_field('player_city', $post->ID) ,  ", " , the_field('player_state', $post->ID); ?></td>
    		<td><?php the_field('player_phone', $post->ID); ?></td>
    		<td><?php the_field('player_email', $post->ID); ?></td>
               </tr>
         <?php endforeach; ?>
    <?php endif; ?>
  • Looks like just a minor typo possibly. In your first <td> you’ll need to echo your values. Also, the permalink variable was not declared. Might try:

    
    if( $posts ):
        foreach( $posts as $post ):
    	$fww_title = get_the_title( $post->ID );
    ?>
    	   <tr>
    		<td><a href="<?php echo get_permalink( $post->ID ); ?>"><?php echo $fww_title; ?></a></td>
    		<td>test</td>
    		<td><?php the_field('player_gender', $post->ID); ?></td>
    		<td><?php the_field('player_level', $post->ID);  ?></td>
    		<td><?php the_field('player_city', $post->ID); ?>, <?php the_field('player_state', $post->ID); ?></td>
    		<td><?php the_field('player_phone', $post->ID); ?></td>
    		<td><?php the_field('player_email', $post->ID); ?></td>
               </tr>
         <?php endforeach; ?>
    <?php endif; ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘get_the_title($post->ID) only shows outside my loop’ is closed to new replies.