Try this code :
<span class="td-author-date">
<?php if( $author_photo != '' ) { echo $this->get_author_photo(); } ?>
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
<?php $concertlocatie = the_field( "concertlocatie" , $this->post->ID ); //etc...?>
<?php if ( $concertlocatie ) : ?><span class="metacelocation"><?php echo $concertlocatie; ?></span><?php endif; ?>
<?php echo $this->get_comments();?>
</span>
You were placing <?php endif; ?>
before </span>
Please correct if i am wrong ??
]]>Can you please try get_field
instead of the_field
?
Ref : https://www.advancedcustomfields.com/resources/get_field/
]]>This can be seen under the foto of Grate Van Fleet here: https://v2.enola.be/
]]><?php print_r( $concertlocatie ); ?>
, then review the resulting output. Determine the key associated with the value you want to output. Use the key to target what part of the array to output. For example, if we find the key is “term_name”, do this in your code:<?php echo $concertlocatie['term_name']; ?>
]]>
the print r function revealed this
” [0] => Ancienne Belgique, Brussel ”
I found it odd to be just simply [0], but sure enough after inserting this into the code the span class AND additional comma appeared like magic.
After literally spending 2 days cracking this nut I can’t thank you enough.
If anybody else ever comes across this problem, this was my final solution
<span class="td-author-date">
<?php if( $author_photo != '' ) { echo $this->get_author_photo(); } ?>
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
<?php $concertlocatie = get_field( "concertlocatie" , $this->post->ID ); //etc...?>
<?php if ( $concertlocatie ) : ?><span class="metacelocation"><?php echo $concertlocatie['0']; ?></span><?php endif; ?>
<?php echo $this->get_comments();?>
</span>
]]>
FWIW, to be 100% correct, don’t use quotes for array index numbers, only associative array keys. $concertlocatie[0]
It works with or without because PHP is a loosely typed language. The difference between strings and integers and other data types is not strictly enforced. But since the array was indexed, the 0 is an integer and no quotes is the proper expression.
I was expecting an associative array keyed by strings:
” [‘term_name’] => Ancienne Belgique, Brussel ”
hence the quotes. I expected wrong ??