mardi 31 mars 2015

Getting ACF field value in functions.php

I try to add a link to a file (uploaded in ACF field) in a Gravity form notification, in Wordpress.


So, as given in Gravity form and ACF documentation, I tried in my functions.php to add a hook to the gravity form notification mail function :



add_filter( 'gform_notification_1', 'my_gform_add_link', 10, 3 );
function my_gform_add_link( $notification, $form, $entry ) {
$postID = intval($entry[2]); //return the ID of the post as an int
$notification['message'] .= '\n <a href="'.get_field('spec-file', $postID).'">See this furniture specs</a>';

return $notification;
}


In the code above : $postID works as expected (it returns the expected post ID). The thing is : get_field('spec-file', $postID) (which is the recommended method to get a field value outside the loop - http://ift.tt/1xngHJm) returns empty.


Why ? Any idea ?


EDIT : The post ID wasn't correct, I fixed it and the code above works as expected.


Aucun commentaire:

Enregistrer un commentaire