• 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

ACF & Genesis

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 › ACF & Genesis

This topic is: not resolved

Tagged: ACF, advanced custom fields, genesis_get_custom_field

  • This topic has 6 replies, 4 voices, and was last updated 7 years, 4 months ago by Ben Siegfried.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • May 18, 2016 at 11:50 am #185855
    Ben Siegfried
    Member

    Just working on learning how to use Advanced Custom Fields ACF with Genesis and followed from a few tutorials (Lynda and this forum) the code below and can't get the field I'm trying to show to appear. Does this look correct to you who is more experienced?

    add_action('genesis_after_post', 'custom_field_after_content');
    
    function custom_field_after_content() {
    if ( is_single() && genesis_get_custom_field('info_box_title') )
    echo genesis_get_custom_field('info_box_title');
    }
    May 18, 2016 at 12:29 pm #185858
    Victor Font
    Moderator

    What theme are you using? genesis_after_post is a hooks for the old XHTML themes. If you are using a HTML5 them, you need to use one of the new hooks. http://my.studiopress.com/docs/hook-reference/


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    May 18, 2016 at 1:22 pm #185861
    Ben Siegfried
    Member

    Geez, I should have known about that detail difference, that was the problem. I got it working now.

    Two questions now:
    1. Is "genesis_get_custom_field" a parameter that in the core of genesis now made to work with ACF?
    2. To add additional fields that are part of the field group, do I just add them like this on the line below or create an array or key:value arrangement?

    May 18, 2016 at 11:54 pm #185877
    Brad Dalton
    Participant

    1. genesis_get_custom_field is a genesis specific function which uses get_post_meta not unlike get_field which is a ACF specific function which also uses the WordPress custom field function get_post_meta.

    In Genesis, you can use get_post_meta or genesis_get_custom_field

    You can only use get_field when the ACF plugin is active. When not, your ACF specific custom field functions like get_field will not work.

    Check out line 181 in genesis > lib > functions > options.php

    /**
     * Echo data from a post or page custom field.
     *
     * Echo only the first value of custom field.
     *
     * Pass in a printf() pattern as the second parameter and have that wrap around the value, if the value is not falsy.
     *
     * @since 0.1.3
     *
     * @uses genesis_get_custom_field() Return custom field post meta data.
     *
     * @param string $field          Custom field key.
     * @param string $output_pattern printf() compatible output pattern.
     */
    function genesis_custom_field( $field, $output_pattern = '%s' ) {
    
    	if ( $value = genesis_get_custom_field( $field ) )
    		printf( $output_pattern, $value );
    
    }
    
    /**
     * Return custom field post meta data.
     *
     * Return only the first value of custom field. Return empty string if field is blank or not set.
     *
     * @since 0.1.3
     *
     * @param string $field Custom field key.
     * @param int $post_id Optional. Post ID to use for Post Meta lookup, defaults to get_the_ID()
     *
     * @return string|boolean Return value or empty string on failure.
     */
    function genesis_get_custom_field( $field, $post_id = null ) {
    
    	//* Use get_the_ID() if no $post_id is specified
    	$post_id = empty( $post_id ) ? get_the_ID() : $post_id;
    
    	if ( ! $post_id ) {
    		return '';
    	}
    
    	$custom_field = get_post_meta( $post_id, $field, true );
    
    	if ( ! $custom_field ) {
    		return '';
    	}
    
    	//* Return custom field, slashes stripped, sanitized if string
    	return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) );
    
    }
    

    2. Are you referring to multiple ACF custom fields? If so, i suggest you ask on the ACF forums.


    Tutorials for StudioPress Themes & WooCommerce.

    May 21, 2016 at 10:36 am #186029
    calculator.ltd
    Participant

    Hi,

    Apologies, I'm an uber novice.

    What code do I add to the functions.php file to show custom fields from ACF?

    Thanks.

    May 22, 2016 at 8:45 am #186080
    Brad Dalton
    Participant

    Here http://wpsites.net/web-design/how-to-create-a-custom-field/


    Tutorials for StudioPress Themes & WooCommerce.

    May 22, 2016 at 11:21 am #186092
    Ben Siegfried
    Member

    Thanks Brad!

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 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

© 2023 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