Add custom field to Genesis Featured Post

Fiona

New Member
#1
Hi. I am currently developing a website using Genesis Dynamik and want to include the facility for visitors to submit testimonials (which are set up as posts) via Gravity Forms. So that I can request an identifier (name/initials/nickname etc) from the person submitting the testimonial I have added a custom field "testimonialauthor" to collect this information. I have successfully designed the form and added code to the customfunctions.php file to show the custom field on the archive page:
Code:
add_action( 'genesis_entry_content', 'add_testimonial_author' );
function add_testimonial_author() {
    if ( is_category(array(11,12))) { // testimonials category id
        $my_custom_meta_value = get_post_meta( get_the_ID(), 'testimonialauthor', true );
        if  (!empty( $my_custom_meta_value )) {      
        echo '<p class="testimonial-author"> '.$my_custom_meta_value.'</p>';
        }
        else {}
    }
}
I would like to do the same thing on the Genesis Featured Post image but don't know where to look for the widget equivalent to "genesis_entry_content". Can anyone help?
Thanks.
 
#2
Do you want to add something to the featured post ? Or do something with the featured image ?

A quick explanation of what you’re trying to achieve would help :)
 

Fiona

New Member
#3
Hi Andytc

Thanks for your reply and apologies for the delay in getting back to you.

On the website I am working on testimonials are created as posts with a category "Testimonials" and various subcategories (depending on who the testimonial is for). I have created a custom field called "testimonialauthor", which is populated by a field "Testimonial by:" on a form I have created in Gravity Forms. The idea is that people can submit a testimonial via the website which creates a draft post that can be published with very few tweaks - you can see the form and examples here. The code shown above (plus a bit of CSS) means that the content submitted in the Testimonial by field appears at the bottom of the post on the archive page in purple. Although there are no links to the individual posts the custom field is also displayed similarly at the bottom of the post content. However, when I use the Genesis Featured Post widget (e.g. on the home page at the bottom "What our members say...") the custom field does not appear. What I am looking for is some code for the Custom Functions file to make this appear in the Genesis Featured Post widget. Unfortunately my knowledge of PHP doesn't yet extend to sorting this out!

I hope this has clarified what I'm trying to do. Can you help?

Thanks and best wishes,

Fiona
 
#4
Well , We can do that if we use the alternative version of the 'Featured Posts Widget' , which is this one -

https://en-gb.wordpress.org/plugins/genesis-featured-widget-amplified/

It does the same thing and bit more - so you could switch to that version quite easily. If you try it , the code below will work , it's pretty much the same as your original code with only the 'Hook' and Function name being changed to -

add_action( 'gfwa_after_post_content', 'add_featured_testimonial_author' );

I looked around and couldn't find a hook for the standard version of Featured Posts , but perhaps Siga or Eric might know ?

Anyhoo .... here's the code if using featured widget amplified

PHP:
add_action( 'gfwa_after_post_content', 'add_featured_testimonial_author' );
function add_featured_testimonial_author() {
    if ( is_category(array(11,12))) { // testimonials category id
        $my_custom_meta_value = get_post_meta( get_the_ID(), 'testimonialauthor', true );
        if  (!empty( $my_custom_meta_value )) {     
        echo '<p class="testimonial-author"> '.$my_custom_meta_value.'</p>';
        }
        else {}
    }
}
 
#6
No clue right now , but I’ll take another look at your site and see if I can work out what’s different, I tried that code on a local playground site (Genesis/Extender) and it worked for me , it showed me the author name below the excerpt in the sidebar using the ‘genesis featured widget amplified’ widget targeting posts with the category ‘testimonials’

On another note , I see you’re in Milton Keynes , I’m down the road just outside Toddington.. ... hello neighbor
 

Fiona

New Member
#7
It's a small world! Somehow you always think everyone on this forum is somewhere over the other side of the world, not 10 miles down the road!

I have just tried deactivating all the plugins apart from Genesis Featured Widget Amplified, but that didn't make any difference, so it doesn't appear to be interference from another plugin.
 
#8
Just realised ... the conditional 'if' for the category , if we remove that it will work for you , i was looking at the sidebar on the category archive and single post , so it was showing.

We'll just remove that to show it everywhere.

PHP:
add_action( 'gfwa_after_post_content', 'add_featured_testimonial_author' );
function add_featured_testimonial_author() {
  $my_custom_meta_value = get_post_meta( get_the_ID(), 'testimonialauthor', true );
    if  (!empty( $my_custom_meta_value )) {     
      echo '<p class="testimonial-author"> '.$my_custom_meta_value.'</p>';
    }
    else {}
}