My code
<`li><img src="<?php echo get_post_meta($post->ID, '_for-gallery', true); ?> " alt=""></li>`
The code should give this:-
<img src="Array" alt="" draggable="false">
But the code is giving this:-
<img src=" " alt="" draggable="false">
2
Answers
Look at the code reference for
get_post_meta()
– it says that the function will return an array if the 3rd parameter ($single
) isfalse
:In your code you’re sending
true
, try this instead:More info here: https://developer.wordpress.org/reference/functions/get_post_meta/
When you use
get_post_meta
function with $single as true just get the first element, but false get all elements separated by comma.Looking your code, i suppose that custom_field is an url, in that case, why you need get an array as a url? you must get a string…
You can check here: https://developer.wordpress.org/reference/functions/get_post_meta/