Community Forums › Forums › Archived Forums › Design Tips and Tricks › ACF & Genesis
- This topic has 6 replies, 4 voices, and was last updated 8 years, 9 months ago by
Ben Siegfried.
-
AuthorPosts
-
May 18, 2016 at 11:50 am #185855
Ben Siegfried
ParticipantJust 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 #185858Victor Font
ModeratorWhat 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 #185861Ben Siegfried
ParticipantGeez, 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 #185877Brad Dalton
Participant1. 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.
May 21, 2016 at 10:36 am #186029calculator.ltd
ParticipantHi,
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 #186080Brad Dalton
ParticipantMay 22, 2016 at 11:21 am #186092Ben Siegfried
ParticipantThanks Brad!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.