Community Forums › Forums › Archived Forums › Design Tips and Tricks › Using ACF but the custom field value is not displaying between the html tags
Tagged: Custom fields
- This topic has 4 replies, 2 voices, and was last updated 8 years, 3 months ago by ndmdn.
-
AuthorPosts
-
December 30, 2015 at 1:17 am #175149ndmdnMember
I am trying to display a Custom Field Value from the ACF plugin. It is displaying as Raw Text but is not printing it inside the html tags. I can't figure out why ti would be doing this.
The output looks like this:
<header class="entry-header"> <h2 class="entry-title" itemprop="headline"><a href="http://localhost/MusicSocialChange/members/carlos-chirinos/" rel="bookmark">Carlos Chirinos</a></h2> Founder <p class="lead position"></p> <div class="portfolio-image"><a href="http://localhost/MusicSocialChange/members/carlos-chirinos/" rel="bookmark"><img src="http://localhost/MusicSocialChange/wp-content/uploads/2015/12/profile-placeholder.gif" alt="Carlos Chirinos" /></a></div> </header>
The template section in question looks like this (again I can't figure out why it won't display the custom field value inside the <p class="lead-position"></p> tags) :
http://localhostadd_action( 'genesis_entry_header', 'mscl_show_contact_info' ); function mscl_show_contact_info() { echo '<p class="lead position">' . the_field('member_role') . '</p>'; } // Display Featured image in the entry content add_action( 'genesis_entry_header', 'mscl_show_featured_image' ); function mscl_show_featured_image() { if ( $image = genesis_get_image( 'format=url&size=portfolio' ) ) { printf( '<div class="portfolio-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); } }
December 30, 2015 at 3:09 am #175153Brad DaltonParticipantLooks like your class is missing something like a hyphen
lead position
Also, you should use get_post_meta rather than the_field which only works with ACF
December 30, 2015 at 9:17 am #175188ndmdnMemberHi Brad,
Thanks for the reply, I really appreciate it.
I have updated with the missing hyphen but still no luck. Also, when I use the get_post_meta function no values are returned at all. I really only want to display the ACF values for these entries and it seems like the_field() should do the trick fine based on the documentation but I just can't understand why it would return the correct value but not place it inside the tags, yet still have the tags created seemingly correctly.
Here is the new output and template code:
<h2 class="entry-title" itemprop="headline"> <a href="http://localhost/MusicSocialChange/members/carlos-chirinos/" rel="bookmark">Carlos Chirinos</a> </h2> <p class="lead-position"></p> <div class="portfolio-image"><a href="http://localhost/MusicSocialChange/members/carlos-chirinos/" rel="bookmark"><img src="http://localhost/MusicSocialChange/wp-content/uploads/2015/12/profile-placeholder.gif" alt="Carlos Chirinos" /></a></div> </header>
add_action( 'genesis_entry_header', 'mscl_show_contact_info' ); function mscl_show_contact_info() { echo '<p class="lead-position">' . get_post_meta() . '</p>'; } // Display Featured image in the entry content add_action( 'genesis_entry_header', 'mscl_show_featured_image' ); function mscl_show_featured_image() { if ( $image = genesis_get_image( 'format=url&size=portfolio' ) ) { printf( '<div class="portfolio-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); } }
December 30, 2015 at 9:57 am #175195Brad DaltonParticipantThis should do it:
add_action( 'genesis_entry_header', 'your_function' ); function your_function() { $mr = get_post_meta( get_the_ID(), 'member_role', true ); echo '<p class="lead-position">'. $mr .'</p>'; }
December 30, 2015 at 10:44 am #175199ndmdnMemberThanks so much Brad! That did the trick! I really appreciate it.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.