I need to display an ACF image field via the php function in the dynamic control, but I’m not sure I understand the format to get it.
The field is in a post pointing at by a parameter in the URL E.G. //http:…com/?post_id=123
So investigating further, I found an example that used {echo:a_function()}, so I tried the following in the dynamic content field
{echo: getphoto( {url_parameter:photo_id} )}
with my function as
function getphoto($passed_postId) {
if ( get_field( 'featured_image', $passed_postId ) ) :
return the_field( 'featured_image', $passed_postId );
else :
return "No Featured Image";
endif;
}
still nothing. I tried hust using {url_parameter:photo_id} in a text element, and it shows the url parameter properly, so I’m not sure why I cannot get this to work.
I haven’t found any documentation about using dynamic data in an image widget to try.
So again, I’m getting closer. I found a warning that to use the {echo:} I had to declare the function names that I want to use. OK, at least it’s being called now, but not returning an image!
OR so I thought, it definately was called and then it’s no longer being called. I don’t understand why or how to debug it other than with echos
well, you want the featured image or an ACF image? your mistake is that the get_field function is for retrieving ACF fields. The post thumbnail is a standard wordpress field and you cannot retrieve it with the get_field function.
You wrote about the ACF image in your post… that’s why I made you the code for an ACF image field.
This is the code to get the Thumbnail:
function getphoto() {
if(isset($_GET['post_id'])){
$passed_postId = htmlspecialchars($_GET['post_id']);
$image = get_the_post_thumbnail_url($passed_postId);
if ( !empty($image) ) :
return $image;
else :
return "No Featured Image";
endif;
}
}