Support » Fixing WordPress » Output Different Custom Fields Separately

  • Resolved maxbuxfiy


    I have two custom fields in a post,


    in my single.php file, I wish to place each output in a div class …

    <div class=“a”>
    <div class=“b”>

    How can I do this? I have tried Get_post_meta() but it prints out both as expected 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator keesiemeijer


    Have you tried it like this (inside the loop):

    $customfiled_a = get_post_meta($post->ID, 'customfiled-a', true);
    if ($customfiled_a != '' ) : ?>
    <div class="a">
    <?php echo $customfiled_a; ?>
    <?php endif; ?>


    Get single post meta!

    get_post_meta( $post_ID, $key , $single );

    <div class='a'><?php echo get_post_meta(get_the_ID(), 'field-a', true); ?></div>
    <div class='b'><?php echo get_post_meta(get_the_ID(), 'field-b', true); ?></div>



    I have tried the two and the result comes up blank. It only seems to work with get_post_meta(), could I be doing something wrong?


    <?php global $post; ?>
    <div class='a'><?php echo get_post_meta($post->ID, 'customfiled-a', true); ?></div>
    <div class='b'><?php echo get_post_meta($post->ID, 'customfiled-b', true); ?></div>



    Sorry guys, they are both working. It was an issue of “too much caching”.

    Cleared all the caches and things are OK.

    Thank you

    Pls I am new to wordpress. Can someone please tell me where to locate the file where I can include the php shortcode above? I am using custom field template and advanced custom field plugins

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Output Different Custom Fields Separately’ is closed to new replies.