Hi @shannonr1 thanks for using this plugin ??
Version 2.X.X used text fields for files (the url was used when you selected a file), the shortcode then showed the url of the text field.
The new version 3.X.X stores the attachment id, so as not to depend on the url (which can change over time), this id is used to retrieve the url and show it in the frontend using the shortcode.
This is a native plugin filter, as you see it fetches url from id and returns it in frontend (using shortcode [cpt-field key="FIELD-KEY"]
)
add_filter('cpt_get_field_type_file', function ($output) {
$file_type = get_post_mime_type($output);
$file_types = explode('/', $file_type);
$main_type = isset($file_types[0]) ? $file_types[0] : false;
if ($main_type && $main_type == 'image') {
return wp_get_attachment_image($output, 'full');
}
return wp_get_attachment_url($output);
});
If you’re not using the shortcode and retrieve the meta value from the database (get_post_meta ()
), put this function in the child theme’s functions.php file:
function get_file_url_from_cpt_meta($meta_value = null)
{
if (get_post($meta_value)) { // Meta is file id
return wp_get_attachment_url($meta_value);
}
// Meta is url (plugin v2.x.x)
return $meta_value;
}
And use this function in the template where you show the url:
<a id="link_button-41-44" class="ct-link-button" href="<?php echo get_file_url_from_cpt_meta($YOUR_META_VALUE); ?>" target="_blank">Download PDF</a>
If the problem is not resolved, create temporary credentials and submit them via the suggestion form on our website.
Sorry for the inconvenience caused by version 3.x.x, as you can see we have improved the core, performance, security, UX and extensibility of the plugin functions.
If you find the plugin useful and want to support the project don’t forget to leave your 5 star review ( it’s really important ? ).
If you want to give more support:
– Make a donation (like a coffee);
– Get the PRO version;