WordPress: Get the file name from get_post_meta custom field

Last updated on

get_post_meta returns the ID of the post attachment. To get the file name of a custom field called pdf:

$doc_id = get_post_meta( get_the_ID(), 'pdf', true );
$filename = basename( get_attached_file( $doc_id ) );
echo $filename;

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

Leave a reply

Your email address will not be published.