• Hi, I’ll try to keep it short and clear.

    I need to add a button in the edit post screen which allows the user to see all the post data in a print-friendly template.
    It’s a custom post type with lots of custom fields.

    The button is not a problem, I think I’ll add it to the admin bar.
    The problem is with the custom template.

    I’ll explain my possible solution but I think there are better methods.

    I create a plugin with a custom PHP file with the “print-friendly” template and I call this file when I click on the button. I’ll pass the post ID in a URL parameter.

    So, the button link will be something like this: https://mywebsite.com/path/to/plugin/print-friendly.php?id=1234

    When the user clicks on the button, a new tab opens with my print-friendly template and the post data. Then the user can print it using the browser print functionality.

    The issue is that in my custom PHP file I can’t use the WordPress functions. I’ll need to include the “wp-load” file in order to do this.

    I know that using a custom PHP file and the including “wp-load” is not a good thing to do.

    Any advices?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Instead of the button linking to ?id=1234, can you build all the post data into the button URL as query variables, and use your template to pull the data out of the URL?

    For example: ...print-friendly.php?title=TITLE&field1=FIELD-VALUE, etc.

    Thread Starter Pacicio

    (@pacicio)

    Good idea, I’m going to try. I only hope that 20+ fields in a URL don’t break everything

    Hi Pacicio:

    I have the exact same need you describe in your first post but I am not good on coding. Please, could you give a little more detail on how you finally got the work done?

    Thanks a lot in advance!
    Luis

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Print post from admin with custom template’ is closed to new replies.