Making a custom field appear in a post

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

This topic is: not resolved

This topic contains 8 replies, has 3 voices, and was last updated by  webmonkey 2 years, 10 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #9820


    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?



    When I used custom fields, I followed these instructions. Not sure if this will help you at all, but check it out –



    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



    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(); ?-->


    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.


    Bill Murray

    See my reply in this thread.

    Web: or Twitter: @wpperform

    We do managed WordPress hosting.



    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?

    $custom-field1 = genesis_get_custom_field (‘custom-field1′);
    echo “Label: ” .$custom-field1[0]. ;


    Bill Murray

    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: or Twitter: @wpperform

    We do managed WordPress hosting.



    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
    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.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.