Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Best Markup for Echoing Custom Fields in WP

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34184
    realph
    Participant

    Just out of interest, what would be the best way to semantically echo custom fields in a WordPress theme.

    At the moment I’m using this, with “blueberries” being my custom field.

    
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'blueberries', true);
    ?>

    Courtesy of WPRecipes.

    I guess what I’m asking is, is there a shorter bit of markup I could use?

    #86142
    TheDoc
    Member

    Here are a few examples on this site:
    https://css-tricks.com/snippets/wordpress/using-custom-fields/

    I prefer checking to see if the value exists first, but based on what you’ve posted it doesn’t look like you need that.

    #86155
    realph
    Participant

    @TheDoc, Cheers dude!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.