I'm using this script to get image filename, stored in a custom meta called background:

$background = get_post_meta( '22', 'background', true );
echo $background;

But it is returning the id of the image, not his filename.

1 Answer 1


background is not a Core meta field. Since you say that get_post_meta( '22', 'background', true ); returns an image ID, I can only assume that whatever saved that value saved the image ID and not the filename.

You can convert the filename to an URL with wp_get_attachment_url() or get other information including a partial file name with wp_get_attachment_metadata()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.