• 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

How to display a Custom Field value in archive

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 › General Discussion › How to display a Custom Field value in archive

This topic is: resolved

Tagged: Archived Content, Custom fields

  • This topic has 5 replies, 2 voices, and was last updated 11 years, 9 months ago by mikeferg.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • January 3, 2015 at 10:09 am #135930
    mikeferg
    Member

    Hello All,

    I am very new to Genesis and I am just starting to get a feel for it.

    So far I have found out how to display my posts as a grid and also how to have the post title display below the post thumbnail on archived pages.

    Here is the question: I have added a custom field to my post called 'price'. How would get this custom field to show with archived content? So that each post in the archive grid will have 'Thumbnail', 'Title' and 'Price'.

    Thanks in advance for any help.
    Mike

    http://www.starg8.co.uk/genesis/
    January 3, 2015 at 12:58 pm #135937
    Ren Ventura
    Member

    You could do something like add it to the Post Info. If that doesn't work, see the Visual Hook Guide for the various areas you can hook into. Also, since you only want it to display on the archive, you can use is_post_type_archive().

    Post Info

    http://genesistutorials.com/visual-hook-guide/blog/

    http://codex.wordpress.org/Function_Reference/is_post_type_archive


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    January 4, 2015 at 4:49 am #135994
    mikeferg
    Member

    Hi Ren, thanks for the reply.

    I worded my question poorly. The custom field needs to display in both post and post archive.

    I have got it to display in the post by adapting this bit of code and placing it in child functions.php:
    add_action( 'genesis_entry_header', 'custom_field_before_content', 15 );
    /**
    * @author Brad Dalton
    * @example http://wpsites.net/
    * @copyright 2014 WP Sites
    */
    function custom_field_before_content() {
    if ( is_singular(array( 'post', 'page')) && genesis_get_custom_field('price') ) :
    echo '<div class="price">£ '. genesis_get_custom_field('price') .'</div>';
    endif;
    }

    I am now looking for a similar bit of code to echo a custom field in a post archive. That is where I am stuck now.

    I followed your links but was unable to find the solution I am looking for. I am still getting to grips with how Genesis does things so the solution may well be staring me in the face but I just can't see it.

    Cheers
    Mike

    January 4, 2015 at 2:38 pm #136055
    Ren Ventura
    Member

    Ah, okay. Use get_post_type() instead of is_singular(). For example:

    if ( 'post' == get_post_type() ) {
    	// Code
    }
    

    get_post_type() will return true if whatever being shown is either singular or an archive. Basically, it is equal to:

    if ( is_singular( 'post' ) || is_post_type_archive( 'post' ) )


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    January 5, 2015 at 11:38 am #136117
    mikeferg
    Member

    Thanks Ren, I think this topic can close now.

    January 6, 2015 at 8:58 am #136187
    mikeferg
    Member

    Ren, I forgot to post up my block of code should anyone else wish to do something similar.

    // Adds custom field "price" to single posts and post archives
    add_action( 'genesis_entry_header', 'custom_field_before_content', 15 );
    function custom_field_before_content() {
    if ( 'post' == get_post_type() )
    echo '<div class="price">£ '. genesis_get_custom_field('price') .'</div>';
    }

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘How to display a Custom Field value in archive’ is closed to new 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