[Resolved] echo custom field not showing in Elements hook

Home Forums Support echo custom field not showing in Elements hook

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #970852
    Pete

    I’ve got the following code to be displayed on ‘blog’ pages (before content). The featured image and post author display but the custom field doesn’t (but the post thumb and taxonomy do). If I place this code in content.php then it does display

    <?php if ( the_post_thumbnail('thumbnail', array('class' => 'alignleft')) ) {	the_post_thumbnail(); } ?>
    
    <?php the_author(); ?> from 
    <?php if( get_post_meta($post->ID, "state", true) ): ?>
    <?php echo get_post_meta($post->ID, "state", true); ?>
    <?php else: ?>nothing<?php endif; ?>
    #971278
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this instead:

    <?php if ( has_post_thumbnail() ) {
        the_post_thumbnail( 'thumbnail', array( 'class' => 'alignleft' ) );
    } ?>
    
    <?php the_author(); ?> from 
    <?php if ( get_post_meta( get_the_ID(), "state", true ) ): ?>
        <?php echo get_post_meta( get_the_ID(), "state", true ); ?>
    <?php else: ?>nothing<?php endif; ?>

    Let me know 🙂

    #971912
    Pete

    Yup works well Tom. Thanks.

    #972294
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.