-
-
Save MjHead/525db5dd35d3076a74c79cae6ff89086 to your computer and use it in GitHub Desktop.
<?php | |
add_filter( 'jet-engine/listings/allowed-callbacks', 'jet_add_attachment_link_callback', 10, 2 ); | |
function jet_add_attachment_link_callback( $callbacks ) { | |
$callbacks['jet_get_attachment_file_link'] = 'Get attachment file link by ID'; | |
return $callbacks; | |
} | |
function jet_get_attachment_file_link( $attachment_id ) { | |
$url = wp_get_attachment_url( $attachment_id ); | |
$name = basename( $url ); | |
return sprintf( '<a href="%1$s">%2$s</a>', $url, $name ); | |
} |
One more question: What if I want to show the title of the custom post type and then add to that the link of the media from the media field? So combining two different sources. (The pdf files do have long names which I don't want to show in a listing)
What I don't understand: If I choose "title" as source I still can choose "Get attachment file link by ID" in the callback field, but then the title goes empty. Why is that? Even if the callback isn't valid the title should still show, does it? Same goes if I choose "Embed URL" as callback: title field goes empty. Maybe I don't quite understand what a callback technically is....
Thanks a lot!
Would be great if the "Dynamic Link" widget would give us the possibility to fetch the URL of the media field. If we now choose the media field as source the ID is being outputted. By using the "Dynamic Link" widget even the added icon would be wrapped into the link which would be great!
https://prnt.sc/rbxlng
Good morning, is this function able to fetch all the files of the post or just one?
Fantastic! Thanks VERY much!