• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Making a custom field appear in a post

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Making a custom field appear in a post

This topic is: not resolved
  • This topic has 8 replies, 3 voices, and was last updated 13 years, 4 months ago by webmonkey.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • January 5, 2013 at 6:48 pm #9820
    webmonkey
    Participant

    I've literally spent days on what should be a simple task.

    I have a bunch of custom field values that I'd like to display, in an order I select, conditionally (if present), under the title of a post, eg.

    Title of WordPress Post
    Artist: John Smith
    Year created: 2006
    Condition: Good
    Price: $500

    I stuck the following code in Genesis Simple Hooks' genesis_after_post_title Hook and set it to Execute PHP:

    <?php echo "<div>"; ?>
    <?php $gfmartist = get_post_custom_values("gfm-artist"); ?>
    <?php if ($gfmartist!="") echo "Artist ".$gfmartist[0].", "; ?>
    <?php echo "</div>"; ?>

    Nothing shows up.

    I have tried this on Prose and News child themes. I have searched WordPress Codex perhaps the most impenetrable "help" documents ever written for man or beast, I have read multiple custom field tutorials found on Google (including Studiopress' Nick the Greek's one).

    I don't get it. Presumably this is as simple as adding the code above, and I'm just a little off somewhere?

    January 5, 2013 at 7:00 pm #9824
    AnitaC
    Keymaster

    When I used custom fields, I followed these instructions. Not sure if this will help you at all, but check it out - http://codex.wordpress.org/Custom_Fields.


    Need help with customization or troubleshooting? Reach out to me.

    January 5, 2013 at 7:38 pm #9829
    webmonkey
    Participant

    Thanks anitac, but that was the impenetrable WordPress Codex page I was talking about. I've worked down that page trying all the various codes in various permutations with no luck at all.

    WordPress' Codex has some ridiculous blindspots, probably because the codex is written by programmers and not technical writers.

    Notice that on this specific page, there's no simple copy and paste code snippet in the entire page that returns a single custom field when placed in a template. The page instead starts with a minimalist post_meta command—which does nothing as is that I can see—and then skips to advanced and legacy uses, assuming a bunch of knowledge that isn't linked.

    My favorite part on that page is:
    <?php echo get_post_meta($post->ID, 'key', true); ?>
    will echo the value for a single key as a string wherever it is used in a template file.

    No it doesn't.

    <?php $key="mykey"; echo get_post_meta($post->ID, $key, true); ?> also fails even though gfm-artist is the custom field name.

    I've tried a bunch of stuff like

    <?php $test = get_post_meta($post->ID, 'gfm-artist', TRUE); ?>
    <?php if($test!="") echo $test; ?>

    Nothing doing. This is the kind of stuff in other CMSes that is dealt with by adding a shortcode like "$gfm-artist$" to a template and you're done. I can't believe it's this difficult and this badly documented.

    Literally days of trying to get this ridiculously simple thing working. I am amazed at the Google fail on this simple issue. Help on the first few pages of Google searches for "display custom field wordpress" is either for legacy WP versions or similarly impenetrably written.

    And hey, StudioPress: the CODE HTML tag in this forum gets confused if you post code with tags. LT and GT angle brackets break the posts, unless you put > etc

    January 5, 2013 at 7:48 pm #9830
    AnitaC
    Keymaster

    If you install and use the Genesis Simple Hooks, you can place the following code in the appropriate Hook area. Here is the Hook Guide.

    <!--?php the_meta(); ?-->
    

    Need help with customization or troubleshooting? Reach out to me.

    January 5, 2013 at 7:52 pm #9832
    AnitaC
    Keymaster

    I see you said above you had installed Simple Hooks already. You are trying to call the Meta I believe but that's not in your code anywhere. I am just sharing how I got mine to work.


    Need help with customization or troubleshooting? Reach out to me.

    January 5, 2013 at 10:19 pm #9874
    Bill Murray
    Member

    See my reply in this thread.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    January 8, 2013 at 3:02 pm #10448
    webmonkey
    Participant

    Thanks Bill.

    You say:

    Make $post global and use the function genesis_get_custom_field(), as in genesis_get_custom_field( ‘myfield’ )

    I didn't understand the "Make $post global" part. Assuming a custom field is called custom-field1, and I want the page to return:

    Label: [custom-field1 value]

    ...does this look about right?

    <?php
    $custom-field1 = genesis_get_custom_field ('custom-field1');
    echo "Label: " .$custom-field1[0]. ;
    ?>

    January 8, 2013 at 3:08 pm #10451
    Bill Murray
    Member

    You need this line in that block of code:

    global $post;
    

    It also looks like you have an extra period after your closing bracket.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    January 8, 2013 at 4:23 pm #10474
    webmonkey
    Participant

    Thanks Bill, bit of solution crossover here. Here's what ended up working:

    1. <?php
    2. if( genesis_get_custom_field( 'CUSTOMFIELDNAME' ))
    3. echo 'Artist: ' .genesis_get_custom_field( 'CUSTOMFIELDNAME' ).;
    4. ?>

    This returns
    Artist: CUSTOMFIELDVALUE
    on a page

    In the Nick the Greek tutorial, where this code was taken from, please note that the second close bracket on line 2 above is missing. The above code is correct.

    How I Make Custom Fields Easier in Genesis

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble