Skip Navigation

[Resolved] get_post_meta() for Types image fields does not work

This thread is resolved. Here is a description of the problem and solution.

Problem: Custom field image URLs with special German characters do not work when displayed as images on the site.

Solution: Ensure a meta tag for charset UTF-8 is added in your site header.

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#601980

Hi,

I don't want to use types API. I need get_post_meta for image-field.

get_post_meta( $id, "wpcf-img-field",true );

Img field has single value, therefore is "true" in get_post_meta. I get also IMG src from database, but problem is, that in IMG SRC are german characters. e.g. hidden link and this cannot render correct in html, therefore I cannot see IMG. Also in src is "–" (Mac Dash with ALT+Dash or html "en dash") -> marked bold. How can I get and render images src in html correct ?

I tried utf8_decode( get_post_meta($szbID,"wpcf-szenenbild",true) ); but this renders "en dash" as "?"

best regards

#602022
Screen Shot 2017-12-28 at 11.16.09 AM.png
öpsü-groß-––-häns.jpg

Hi, I will be glad to help but I need some more information. Here's what I did to try to replicate a problem with an img src URL containing special characters.

First I created an image file using the same name you provided. Please find the file attached.

Then I added the image as a custom field in a post. My field slug is "img-1". I added this content to a post in the "text" tab:

Types field: [types field='img-1' separator=', ' output='raw'][/types]<br />

SRC shortcode: [german_src]<br />

Image with src shortcode: <img src="[german_src]" /><br />

To test it out, I created a custom shortcode "german_src" using this PHP:

add_shortcode( 'german_src', 'german_src_func' );
function german_src_func() {
  $src = get_post_meta(310, 'wpcf-img-1', true);
  return $src;
}

My post ID is 310. So you can see that I'm returning the URL of the image to be used as the src attribute in an img tag. It seems to be working for me. Please find the results attached as a screenshot. I don't see a problem with the image src attribute, so I must be missing something. Can you help me replicate the problem?

#602172

Hi Christian,

you are right, this does work. I tested und checked my HTML and problem was, that I had not meta charset on my website. I added <meta charset="UTF-8"> and now everything works very well.

best regards