Upload and link PDF with custompress

I am trying to upload a pdf file as a custom field and link this to be opened from the front-end. However, I am able to add an image and show this on the front-end. The problem is, when I want to upload a pdf file format it does not gets added to the custom post.
Is this the case, that one can not use pdf's as an upload file and do you know away around it?

Many thanks for your help

  • Sajid

    Hello Ronald,
    Hope you are doing good today :slight_smile:

    I am afraid, other files types are not available at the moment in CustomPress custom fields. However, what you can do is, upload PDF file in Dashboard -> Media, copy the URL and paste in text based custom field created with CustomPress plugin.

    Please note that, you have to get the URL of this field and add in a link to make it downloadable or open in browser by PHP in your template file.

    If you post the ID of your custom text field that you would use for PDF file, I could come up with a custom code snippet for you too to add in the template to include PDF download link/button.

    Take care and have a nice day :slight_smile:

    Best Regards,
    Sajid - WPMU DEV Support

  • Ronald

    Thank you Sajid for your answer.

    Since posting the question I have explored that option that you suggested. Unfortunately my php skills are super minimal and I did struggle to come up with the right code. So far I have this but it is not working yet. I would like to go back to basics on php but if only I had more time....

    <p class"file_upload">
    									<?php '<a href="'.do_shortcode('[ct id="ct_File_Uploa_text_8dc8" property="title | description | value"]').'"</a>'; ?>
    									</p>

    If I could it to work, then I could CSS a button... Though is it possible to make it a button from the php file? I use UIkit as a styler.
    So a normal button html markup would be ... and have the text set as 'View Policy'

    I hope it makes sense, it would be amazing to get it that far and I appreciate your help!

  • Sajid

    Hello Ronald,
    Hope you are doing good today :slight_smile:

    It appeared to be easier than I thought at first. You don't need any advanced knowledge of PHP to have a PDF link.

    Just add following in single.php or content-single.php file of your theme (assuming you want to display on default post detail page).

    <a href="Replace this upload field shortcode">PDFDownloadLink</a>

    Now, as started in the code, replace the text with the shortcode. You can get the shortcode of this field from CustomPress -> Content Types -> Custom Fields -> Embed Code (remember its the one with do_shortcode function for templates) (see screenshot).

    The final code should look like this:
    <a href="<?php echo do_shortcode('[ct id="_ct_text_5884991a23293" property="value"]'); ?>">PDFDownloadLink</a>

    Note: You can add this code in any template file where ever you want to display the download button.

    Take care and have a nice day :slight_smile:

    Best Regards,
    Sajid - WPMU DEV Support

  • Ronald

    Excuses for the late reply. There is an issue I am stumbling on.

    When I past the link

    <a href="[ct id="ct_File_Uploa_text_8dc8" property="value"]">click here</a>

    as provided in your reply > save > click the link on the front-end and it and outputs it as

    http://blockley.webbees.uk/policies/aa/ct%20id=

    When I save it in PHP it just links it to the page url...

    I have tried to disable all plugins to see if there is a shortcode conflict, but without luck. Do you have any idea where I am going wrong? Many Thanks -R

  • Ronald

    Hi Sajid,
    I had another go and this final code worked - I expect that somehow I made a mistake within the policy.single.php file that I created to cause an error within the link.

    So, thank you for helping me on my way - I think I learned a lot more through this exercise.

    <a href="<?php echo do_shortcode('[ct id="ct_File_Uploa_text_8dc8" property="title | description | value"]'); ?>"><i class="uk-icon-check-square-o"></i> View Policy</a>

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.